blob: 2270144d7286d44c1994cb5193f7d76fd349b3dc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * video.c - ACPI Video Driver ($Revision:$)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
Thomas Tuttlef4715182006-12-19 12:56:14 -08006 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/list.h>
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -050032#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/proc_fs.h>
34#include <linux/seq_file.h>
Luming Yue9dab192007-08-20 18:23:53 +080035#include <linux/input.h>
Yu Luming2f3d0002006-11-11 02:40:34 +080036#include <linux/backlight.h>
Luming Yu23b0f012007-05-09 21:07:05 +080037#include <linux/video_output.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/uaccess.h>
39
40#include <acpi/acpi_bus.h>
41#include <acpi/acpi_drivers.h>
42
43#define ACPI_VIDEO_COMPONENT 0x08000000
44#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define ACPI_VIDEO_BUS_NAME "Video Bus"
46#define ACPI_VIDEO_DEVICE_NAME "Video Device"
47#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48#define ACPI_VIDEO_NOTIFY_PROBE 0x81
49#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
52
Thomas Tuttlef4715182006-12-19 12:56:14 -080053#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60#define ACPI_VIDEO_HEAD_END (~0u)
Yu Luming2f3d0002006-11-11 02:40:34 +080061#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Rui Zhang82cae992007-01-03 23:40:53 -050063#define ACPI_VIDEO_DISPLAY_CRT 1
64#define ACPI_VIDEO_DISPLAY_TV 2
65#define ACPI_VIDEO_DISPLAY_DVI 3
66#define ACPI_VIDEO_DISPLAY_LCD 4
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050069ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Len Brownf52fd662007-02-12 22:42:12 -050071MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050072MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073MODULE_LICENSE("GPL");
74
Len Brown4be44fc2005-08-05 00:44:28 -040075static int acpi_video_bus_add(struct acpi_device *device);
76static int acpi_video_bus_remove(struct acpi_device *device, int type);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Thomas Renninger1ba90e32007-07-23 14:44:41 +020078static const struct acpi_device_id video_device_ids[] = {
79 {ACPI_VIDEO_HID, 0},
80 {"", 0},
81};
82MODULE_DEVICE_TABLE(acpi, video_device_ids);
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050085 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020087 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 .ops = {
89 .add = acpi_video_bus_add,
90 .remove = acpi_video_bus_remove,
Len Brown4be44fc2005-08-05 00:44:28 -040091 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -040095 u8 multihead:1; /* can switch video heads */
96 u8 rom:1; /* can retrieve a video rom */
97 u8 post:1; /* can configure the head to */
98 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
101struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400102 u8 _DOS:1; /*Enable/Disable output switching */
103 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
104 u8 _ROM:1; /*Get ROM Data */
105 u8 _GPD:1; /*Get POST Device */
106 u8 _SPD:1; /*Set POST Device */
107 u8 _VPO:1; /*Video POST Options */
108 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109};
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111struct acpi_video_device_attrib {
112 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100113 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400114 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100115 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400116 u32 bios_can_detect:1; /*BIOS can detect the device */
117 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
118 the VGA device. */
119 u32 pipe_id:3; /*For VGA multiple-head devices. */
120 u32 reserved:10; /*Must be 0 */
121 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122};
123
124struct acpi_video_enumerated_device {
125 union {
126 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400127 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 } value;
129 struct acpi_video_device *bind_info;
130};
131
132struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400133 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400134 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400136 u8 attached_count;
137 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400139 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500140 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400141 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800142 struct input_dev *input;
143 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144};
145
146struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400147 u8 crt:1;
148 u8 lcd:1;
149 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500150 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400151 u8 bios:1;
152 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500153 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154};
155
156struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400157 u8 _ADR:1; /*Return the unique ID */
158 u8 _BCL:1; /*Query list of brightness control levels supported */
159 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800160 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400161 u8 _DDC:1; /*Return the EDID for this device */
162 u8 _DCS:1; /*Return status of output device */
163 u8 _DGS:1; /*Query graphics state */
164 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165};
166
167struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400168 int curr;
169 int count;
170 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400174 unsigned long device_id;
175 struct acpi_video_device_flags flags;
176 struct acpi_video_device_cap cap;
177 struct list_head entry;
178 struct acpi_video_bus *video;
179 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800181 struct backlight_device *backlight;
Luming Yu23b0f012007-05-09 21:07:05 +0800182 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183};
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185/* bus */
186static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
187static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400188 .open = acpi_video_bus_info_open_fs,
189 .read = seq_read,
190 .llseek = seq_lseek,
191 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192};
193
194static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
195static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400196 .open = acpi_video_bus_ROM_open_fs,
197 .read = seq_read,
198 .llseek = seq_lseek,
199 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
Len Brown4be44fc2005-08-05 00:44:28 -0400202static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
203 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400205 .open = acpi_video_bus_POST_info_open_fs,
206 .read = seq_read,
207 .llseek = seq_lseek,
208 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209};
210
211static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
212static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400213 .open = acpi_video_bus_POST_open_fs,
214 .read = seq_read,
215 .llseek = seq_lseek,
216 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217};
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
220static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400221 .open = acpi_video_bus_DOS_open_fs,
222 .read = seq_read,
223 .llseek = seq_lseek,
224 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225};
226
227/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400228static int acpi_video_device_info_open_fs(struct inode *inode,
229 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400231 .open = acpi_video_device_info_open_fs,
232 .read = seq_read,
233 .llseek = seq_lseek,
234 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235};
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237static int acpi_video_device_state_open_fs(struct inode *inode,
238 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400240 .open = acpi_video_device_state_open_fs,
241 .read = seq_read,
242 .llseek = seq_lseek,
243 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244};
245
Len Brown4be44fc2005-08-05 00:44:28 -0400246static int acpi_video_device_brightness_open_fs(struct inode *inode,
247 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400249 .open = acpi_video_device_brightness_open_fs,
250 .read = seq_read,
251 .llseek = seq_lseek,
252 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253};
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255static int acpi_video_device_EDID_open_fs(struct inode *inode,
256 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400258 .open = acpi_video_device_EDID_open_fs,
259 .read = seq_read,
260 .llseek = seq_lseek,
261 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262};
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 "motherboard VGA device",
266 "PCI VGA device",
267 "AGP VGA device",
268 "UNKNOWN",
269};
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
272static void acpi_video_device_rebind(struct acpi_video_bus *video);
273static void acpi_video_device_bind(struct acpi_video_bus *video,
274 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Len Brown4be44fc2005-08-05 00:44:28 -0400276static int acpi_video_switch_output(struct acpi_video_bus *video, int event);
Yu Luming2f3d0002006-11-11 02:40:34 +0800277static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
278 int level);
279static int acpi_video_device_lcd_get_level_current(
280 struct acpi_video_device *device,
281 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400282static int acpi_video_get_next_level(struct acpi_video_device *device,
283 u32 level_current, u32 event);
284static void acpi_video_switch_brightness(struct acpi_video_device *device,
285 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800286static int acpi_video_device_get_state(struct acpi_video_device *device,
287 unsigned long *state);
288static int acpi_video_output_get(struct output_device *od);
289static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Yu Luming2f3d0002006-11-11 02:40:34 +0800291/*backlight device sysfs support*/
292static int acpi_video_get_brightness(struct backlight_device *bd)
293{
294 unsigned long cur_level;
295 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100296 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800297 acpi_video_device_lcd_get_level_current(vd, &cur_level);
298 return (int) cur_level;
299}
300
301static int acpi_video_set_brightness(struct backlight_device *bd)
302{
Richard Purdie599a52d2007-02-10 23:07:48 +0000303 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800304 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100305 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800306 acpi_video_device_lcd_set_level(vd, request_level);
307 return 0;
308}
309
Richard Purdie599a52d2007-02-10 23:07:48 +0000310static struct backlight_ops acpi_backlight_ops = {
311 .get_brightness = acpi_video_get_brightness,
312 .update_status = acpi_video_set_brightness,
313};
314
Luming Yu23b0f012007-05-09 21:07:05 +0800315/*video output device sysfs support*/
316static int acpi_video_output_get(struct output_device *od)
317{
318 unsigned long state;
319 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700320 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800321 acpi_video_device_get_state(vd, &state);
322 return (int)state;
323}
324
325static int acpi_video_output_set(struct output_device *od)
326{
327 unsigned long state = od->request_state;
328 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700329 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800330 return acpi_video_device_set_state(vd, state);
331}
332
333static struct output_properties acpi_output_properties = {
334 .set_state = acpi_video_output_set,
335 .get_status = acpi_video_output_get,
336};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337/* --------------------------------------------------------------------------
338 Video Management
339 -------------------------------------------------------------------------- */
340
341/* device */
342
343static int
Len Brown4be44fc2005-08-05 00:44:28 -0400344acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Len Brown4be44fc2005-08-05 00:44:28 -0400346 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400347
348 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Patrick Mocheld550d982006-06-27 00:41:40 -0400350 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
353static int
Len Brown4be44fc2005-08-05 00:44:28 -0400354acpi_video_device_get_state(struct acpi_video_device *device,
355 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356{
Len Brown4be44fc2005-08-05 00:44:28 -0400357 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Patrick Mochel90130262006-05-19 16:54:48 -0400359 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Patrick Mocheld550d982006-06-27 00:41:40 -0400361 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364static int
Len Brown4be44fc2005-08-05 00:44:28 -0400365acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Len Brown4be44fc2005-08-05 00:44:28 -0400367 int status;
368 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
369 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400370 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400374 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Patrick Mocheld550d982006-06-27 00:41:40 -0400376 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
379static int
Len Brown4be44fc2005-08-05 00:44:28 -0400380acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
381 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Len Brown4be44fc2005-08-05 00:44:28 -0400383 int status;
384 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
385 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 *levels = NULL;
389
Patrick Mochel90130262006-05-19 16:54:48 -0400390 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400392 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400393 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500394 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400395 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 status = -EFAULT;
397 goto err;
398 }
399
400 *levels = obj;
401
Patrick Mocheld550d982006-06-27 00:41:40 -0400402 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Len Brown4be44fc2005-08-05 00:44:28 -0400404 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800405 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Patrick Mocheld550d982006-06-27 00:41:40 -0400407 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410static int
Len Brown4be44fc2005-08-05 00:44:28 -0400411acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400413 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400414 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
415 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400420 if (device->cap._BCM)
421 status = acpi_evaluate_object(device->dev->handle, "_BCM",
422 &args, NULL);
423 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400424 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427static int
Len Brown4be44fc2005-08-05 00:44:28 -0400428acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
429 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400431 if (device->cap._BQC)
432 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
433 level);
434 *level = device->brightness->curr;
435 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
438static int
Len Brown4be44fc2005-08-05 00:44:28 -0400439acpi_video_device_EDID(struct acpi_video_device *device,
440 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Len Brown4be44fc2005-08-05 00:44:28 -0400442 int status;
443 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
444 union acpi_object *obj;
445 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
446 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 *edid = NULL;
450
451 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400452 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (length == 128)
454 arg0.integer.value = 1;
455 else if (length == 256)
456 arg0.integer.value = 2;
457 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400458 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Patrick Mochel90130262006-05-19 16:54:48 -0400460 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400462 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200464 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 if (obj && obj->type == ACPI_TYPE_BUFFER)
467 *edid = obj;
468 else {
Len Brown64684632006-06-26 23:41:38 -0400469 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 status = -EFAULT;
471 kfree(obj);
472 }
473
Patrick Mocheld550d982006-06-27 00:41:40 -0400474 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477/* bus */
478
479static int
Len Brown4be44fc2005-08-05 00:44:28 -0400480acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
Len Brown4be44fc2005-08-05 00:44:28 -0400482 int status;
483 unsigned long tmp;
484 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
485 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 arg0.integer.value = option;
489
Patrick Mochel90130262006-05-19 16:54:48 -0400490 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400492 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Patrick Mocheld550d982006-06-27 00:41:40 -0400494 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
497static int
Len Brown4be44fc2005-08-05 00:44:28 -0400498acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
500 int status;
501
Patrick Mochel90130262006-05-19 16:54:48 -0400502 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Patrick Mocheld550d982006-06-27 00:41:40 -0400504 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
507static int
Len Brown4be44fc2005-08-05 00:44:28 -0400508acpi_video_bus_POST_options(struct acpi_video_bus *video,
509 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Len Brown4be44fc2005-08-05 00:44:28 -0400511 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Patrick Mochel90130262006-05-19 16:54:48 -0400513 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 *options &= 3;
515
Patrick Mocheld550d982006-06-27 00:41:40 -0400516 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
519/*
520 * Arg:
521 * video : video bus device pointer
522 * bios_flag :
523 * 0. The system BIOS should NOT automatically switch(toggle)
524 * the active display output.
525 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100526 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 * 2. The _DGS value should be locked.
528 * 3. The system BIOS should not automatically switch (toggle) the
529 * active display output, but instead generate the display switch
530 * event notify code.
531 * lcd_flag :
532 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100533 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100535 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 * Return Value:
537 * -1 wrong arg.
538 */
539
540static int
Len Brown4be44fc2005-08-05 00:44:28 -0400541acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Len Brown4be44fc2005-08-05 00:44:28 -0400543 acpi_integer status = 0;
544 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
545 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Len Brown4be44fc2005-08-05 00:44:28 -0400548 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 status = -1;
550 goto Failed;
551 }
552 arg0.integer.value = (lcd_flag << 2) | bios_flag;
553 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400554 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Len Brown4be44fc2005-08-05 00:44:28 -0400556 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400557 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
560/*
561 * Arg:
562 * device : video output device (LCD, CRT, ..)
563 *
564 * Return Value:
565 * None
566 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100567 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 * device.
569 */
570
Len Brown4be44fc2005-08-05 00:44:28 -0400571static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 acpi_handle h_dummy1;
574 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800575 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 union acpi_object *obj = NULL;
577 struct acpi_video_device_brightness *br = NULL;
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
William Lee Irwin III98934de2007-12-12 03:56:55 -0800580 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Patrick Mochel90130262006-05-19 16:54:48 -0400582 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 device->cap._ADR = 1;
584 }
Patrick Mochel90130262006-05-19 16:54:48 -0400585 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400586 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 }
Patrick Mochel90130262006-05-19 16:54:48 -0400588 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400589 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800591 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
592 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400593 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400594 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
Patrick Mochel90130262006-05-19 16:54:48 -0400596 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 device->cap._DCS = 1;
598 }
Patrick Mochel90130262006-05-19 16:54:48 -0400599 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 device->cap._DGS = 1;
601 }
Patrick Mochel90130262006-05-19 16:54:48 -0400602 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 device->cap._DSS = 1;
604 }
605
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400606 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400608 if (obj->package.count >= 2) {
609 int count = 0;
610 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400611
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400612 br = kzalloc(sizeof(*br), GFP_KERNEL);
613 if (!br) {
614 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400616 br->levels = kmalloc(obj->package.count *
617 sizeof *(br->levels), GFP_KERNEL);
618 if (!br->levels)
619 goto out;
620
621 for (i = 0; i < obj->package.count; i++) {
622 o = (union acpi_object *)&obj->package.
623 elements[i];
624 if (o->type != ACPI_TYPE_INTEGER) {
625 printk(KERN_ERR PREFIX "Invalid data\n");
626 continue;
627 }
628 br->levels[count] = (u32) o->integer.value;
629
630 if (br->levels[count] > max_level)
631 max_level = br->levels[count];
632 count++;
633 }
634 out:
635 if (count < 2) {
636 kfree(br->levels);
637 kfree(br);
638 } else {
639 br->count = count;
640 device->brightness = br;
641 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
642 "found %d brightness levels\n",
643 count));
644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400647
648 } else {
649 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500652 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400654 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800655 unsigned long tmp;
656 static int count = 0;
657 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800658 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
659 if (!name)
660 return;
661
Yu Luming2f3d0002006-11-11 02:40:34 +0800662 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800663 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800664 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000665 NULL, device, &acpi_backlight_ops);
666 device->backlight->props.max_brightness = max_level;
667 device->backlight->props.brightness = (int)tmp;
668 backlight_update_status(device->backlight);
669
Yu Luming2f3d0002006-11-11 02:40:34 +0800670 kfree(name);
671 }
Luming Yu23b0f012007-05-09 21:07:05 +0800672 if (device->cap._DCS && device->cap._DSS){
673 static int count = 0;
674 char *name;
675 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
676 if (!name)
677 return;
678 sprintf(name, "acpi_video%d", count++);
679 device->output_dev = video_output_register(name,
680 NULL, device, &acpi_output_properties);
681 kfree(name);
682 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400683 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684}
685
686/*
687 * Arg:
688 * device : video output device (VGA)
689 *
690 * Return Value:
691 * None
692 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100693 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 */
695
Len Brown4be44fc2005-08-05 00:44:28 -0400696static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697{
Len Brown4be44fc2005-08-05 00:44:28 -0400698 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
William Lee Irwin III98934de2007-12-12 03:56:55 -0800700 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400701 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 video->cap._DOS = 1;
703 }
Patrick Mochel90130262006-05-19 16:54:48 -0400704 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 video->cap._DOD = 1;
706 }
Patrick Mochel90130262006-05-19 16:54:48 -0400707 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 video->cap._ROM = 1;
709 }
Patrick Mochel90130262006-05-19 16:54:48 -0400710 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 video->cap._GPD = 1;
712 }
Patrick Mochel90130262006-05-19 16:54:48 -0400713 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 video->cap._SPD = 1;
715 }
Patrick Mochel90130262006-05-19 16:54:48 -0400716 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 video->cap._VPO = 1;
718 }
719}
720
721/*
722 * Check whether the video bus device has required AML method to
723 * support the desired features
724 */
725
Len Brown4be44fc2005-08-05 00:44:28 -0400726static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Len Brown4be44fc2005-08-05 00:44:28 -0400728 acpi_status status = -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400732 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 /* Since there is no HID, CID and so on for VGA driver, we have
735 * to check well known required nodes.
736 */
737
Julius Volz98fb8fe2007-02-20 16:38:40 +0100738 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400739 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 video->flags.multihead = 1;
741 status = 0;
742 }
743
Julius Volz98fb8fe2007-02-20 16:38:40 +0100744 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400745 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 video->flags.rom = 1;
747 status = 0;
748 }
749
Julius Volz98fb8fe2007-02-20 16:38:40 +0100750 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400751 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 video->flags.post = 1;
753 status = 0;
754 }
755
Patrick Mocheld550d982006-06-27 00:41:40 -0400756 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
758
759/* --------------------------------------------------------------------------
760 FS Interface (/proc)
761 -------------------------------------------------------------------------- */
762
Len Brown4be44fc2005-08-05 00:44:28 -0400763static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765/* video devices */
766
Len Brown4be44fc2005-08-05 00:44:28 -0400767static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200769 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 if (!dev)
773 goto end;
774
775 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
776 seq_printf(seq, "type: ");
777 if (dev->flags.crt)
778 seq_printf(seq, "CRT\n");
779 else if (dev->flags.lcd)
780 seq_printf(seq, "LCD\n");
781 else if (dev->flags.tvout)
782 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500783 else if (dev->flags.dvi)
784 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 else
786 seq_printf(seq, "UNKNOWN\n");
787
Len Brown4be44fc2005-08-05 00:44:28 -0400788 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Len Brown4be44fc2005-08-05 00:44:28 -0400790 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400791 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
794static int
Len Brown4be44fc2005-08-05 00:44:28 -0400795acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
797 return single_open(file, acpi_video_device_info_seq_show,
798 PDE(inode)->data);
799}
800
Len Brown4be44fc2005-08-05 00:44:28 -0400801static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Len Brown4be44fc2005-08-05 00:44:28 -0400803 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200804 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400805 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 if (!dev)
809 goto end;
810
811 status = acpi_video_device_get_state(dev, &state);
812 seq_printf(seq, "state: ");
813 if (ACPI_SUCCESS(status))
814 seq_printf(seq, "0x%02lx\n", state);
815 else
816 seq_printf(seq, "<not supported>\n");
817
818 status = acpi_video_device_query(dev, &state);
819 seq_printf(seq, "query: ");
820 if (ACPI_SUCCESS(status))
821 seq_printf(seq, "0x%02lx\n", state);
822 else
823 seq_printf(seq, "<not supported>\n");
824
Len Brown4be44fc2005-08-05 00:44:28 -0400825 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400826 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827}
828
829static int
Len Brown4be44fc2005-08-05 00:44:28 -0400830acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
832 return single_open(file, acpi_video_device_state_seq_show,
833 PDE(inode)->data);
834}
835
836static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400837acpi_video_device_write_state(struct file *file,
838 const char __user * buffer,
839 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
Len Brown4be44fc2005-08-05 00:44:28 -0400841 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200842 struct seq_file *m = file->private_data;
843 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400844 char str[12] = { 0 };
845 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400849 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400852 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 str[count] = 0;
855 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400856 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 status = acpi_video_device_set_state(dev, state);
859
860 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400861 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Patrick Mocheld550d982006-06-27 00:41:40 -0400863 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864}
865
866static int
Len Brown4be44fc2005-08-05 00:44:28 -0400867acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200869 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400870 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 if (!dev || !dev->brightness) {
874 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400875 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 }
877
878 seq_printf(seq, "levels: ");
879 for (i = 0; i < dev->brightness->count; i++)
880 seq_printf(seq, " %d", dev->brightness->levels[i]);
881 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
882
Patrick Mocheld550d982006-06-27 00:41:40 -0400883 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884}
885
886static int
Len Brown4be44fc2005-08-05 00:44:28 -0400887acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888{
889 return single_open(file, acpi_video_device_brightness_seq_show,
890 PDE(inode)->data);
891}
892
893static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400894acpi_video_device_write_brightness(struct file *file,
895 const char __user * buffer,
896 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200898 struct seq_file *m = file->private_data;
899 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100900 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400901 unsigned int level = 0;
902 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Thomas Renninger59d399d2005-11-08 05:27:00 -0500905 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400906 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400909 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 str[count] = 0;
912 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400913
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400915 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Julius Volz98fb8fe2007-02-20 16:38:40 +0100917 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 for (i = 0; i < dev->brightness->count; i++)
919 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400920 if (ACPI_SUCCESS
921 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 dev->brightness->curr = level;
923 break;
924 }
925
Patrick Mocheld550d982006-06-27 00:41:40 -0400926 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
Len Brown4be44fc2005-08-05 00:44:28 -0400929static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200931 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400932 int status;
933 int i;
934 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937 if (!dev)
938 goto out;
939
Len Brown4be44fc2005-08-05 00:44:28 -0400940 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400942 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 }
944
945 if (ACPI_FAILURE(status)) {
946 goto out;
947 }
948
949 if (edid && edid->type == ACPI_TYPE_BUFFER) {
950 for (i = 0; i < edid->buffer.length; i++)
951 seq_putc(seq, edid->buffer.pointer[i]);
952 }
953
Len Brown4be44fc2005-08-05 00:44:28 -0400954 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 if (!edid)
956 seq_printf(seq, "<not supported>\n");
957 else
958 kfree(edid);
959
Patrick Mocheld550d982006-06-27 00:41:40 -0400960 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
962
963static int
Len Brown4be44fc2005-08-05 00:44:28 -0400964acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965{
966 return single_open(file, acpi_video_device_EDID_seq_show,
967 PDE(inode)->data);
968}
969
Len Brown4be44fc2005-08-05 00:44:28 -0400970static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971{
Len Brown4be44fc2005-08-05 00:44:28 -0400972 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 struct acpi_video_device *vid_dev;
974
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400977 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200979 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -0400981 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 if (!acpi_device_dir(device)) {
984 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -0400985 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -0400987 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 acpi_device_dir(device)->owner = THIS_MODULE;
989 }
990
991 /* 'info' [R] */
992 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
993 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -0400994 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 else {
996 entry->proc_fops = &acpi_video_device_info_fops;
997 entry->data = acpi_driver_data(device);
998 entry->owner = THIS_MODULE;
999 }
1000
1001 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001002 entry =
1003 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1004 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001006 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001008 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 entry->data = acpi_driver_data(device);
1011 entry->owner = THIS_MODULE;
1012 }
1013
1014 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001015 entry =
1016 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1017 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001019 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001021 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 entry->data = acpi_driver_data(device);
1024 entry->owner = THIS_MODULE;
1025 }
1026
1027 /* 'EDID' [R] */
1028 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1029 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001030 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 else {
1032 entry->proc_fops = &acpi_video_device_EDID_fops;
1033 entry->data = acpi_driver_data(device);
1034 entry->owner = THIS_MODULE;
1035 }
1036
Patrick Mocheld550d982006-06-27 00:41:40 -04001037 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038}
1039
Len Brown4be44fc2005-08-05 00:44:28 -04001040static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001044 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001046 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
1048 if (acpi_device_dir(device)) {
1049 remove_proc_entry("info", acpi_device_dir(device));
1050 remove_proc_entry("state", acpi_device_dir(device));
1051 remove_proc_entry("brightness", acpi_device_dir(device));
1052 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001053 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 acpi_device_dir(device) = NULL;
1055 }
1056
Patrick Mocheld550d982006-06-27 00:41:40 -04001057 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058}
1059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001061static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001063 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 if (!video)
1067 goto end;
1068
1069 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001070 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001072 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001074 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Len Brown4be44fc2005-08-05 00:44:28 -04001076 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001077 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
Len Brown4be44fc2005-08-05 00:44:28 -04001080static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081{
Len Brown4be44fc2005-08-05 00:44:28 -04001082 return single_open(file, acpi_video_bus_info_seq_show,
1083 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084}
1085
Len Brown4be44fc2005-08-05 00:44:28 -04001086static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001088 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
1091 if (!video)
1092 goto end;
1093
1094 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1095 seq_printf(seq, "<TODO>\n");
1096
Len Brown4be44fc2005-08-05 00:44:28 -04001097 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001098 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099}
1100
Len Brown4be44fc2005-08-05 00:44:28 -04001101static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
1103 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1104}
1105
Len Brown4be44fc2005-08-05 00:44:28 -04001106static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001108 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001109 unsigned long options;
1110 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113 if (!video)
1114 goto end;
1115
1116 status = acpi_video_bus_POST_options(video, &options);
1117 if (ACPI_SUCCESS(status)) {
1118 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001119 printk(KERN_WARNING PREFIX
1120 "The motherboard VGA device is not listed as a possible POST device.\n");
1121 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001122 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 }
1124 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001125 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 if (options & 2)
1127 seq_printf(seq, " <PCI video>");
1128 if (options & 4)
1129 seq_printf(seq, " <AGP video>");
1130 seq_putc(seq, '\n');
1131 } else
1132 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001133 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001134 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135}
1136
1137static int
Len Brown4be44fc2005-08-05 00:44:28 -04001138acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139{
Len Brown4be44fc2005-08-05 00:44:28 -04001140 return single_open(file, acpi_video_bus_POST_info_seq_show,
1141 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Len Brown4be44fc2005-08-05 00:44:28 -04001144static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001146 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001147 int status;
1148 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 if (!video)
1152 goto end;
1153
Len Brown4be44fc2005-08-05 00:44:28 -04001154 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (!ACPI_SUCCESS(status)) {
1156 seq_printf(seq, "<not supported>\n");
1157 goto end;
1158 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001159 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
Len Brown4be44fc2005-08-05 00:44:28 -04001161 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001162 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Len Brown4be44fc2005-08-05 00:44:28 -04001165static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001167 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
Len Brown4be44fc2005-08-05 00:44:28 -04001170 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
Patrick Mocheld550d982006-06-27 00:41:40 -04001172 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Len Brown4be44fc2005-08-05 00:44:28 -04001175static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
Len Brown4be44fc2005-08-05 00:44:28 -04001177 return single_open(file, acpi_video_bus_POST_seq_show,
1178 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179}
1180
Len Brown4be44fc2005-08-05 00:44:28 -04001181static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
1183 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1184}
1185
1186static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001187acpi_video_bus_write_POST(struct file *file,
1188 const char __user * buffer,
1189 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
Len Brown4be44fc2005-08-05 00:44:28 -04001191 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001192 struct seq_file *m = file->private_data;
1193 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001194 char str[12] = { 0 };
1195 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001199 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 status = acpi_video_bus_POST_options(video, &options);
1202 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001203 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
1205 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001206 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
1208 str[count] = 0;
1209 opt = strtoul(str, NULL, 0);
1210 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001211 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
Julius Volz98fb8fe2007-02-20 16:38:40 +01001213 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 options |= 1;
1215
1216 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001217 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001219 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 }
1222
Patrick Mocheld550d982006-06-27 00:41:40 -04001223 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
1226static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001227acpi_video_bus_write_DOS(struct file *file,
1228 const char __user * buffer,
1229 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230{
Len Brown4be44fc2005-08-05 00:44:28 -04001231 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001232 struct seq_file *m = file->private_data;
1233 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001234 char str[12] = { 0 };
1235 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001239 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001242 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
1244 str[count] = 0;
1245 opt = strtoul(str, NULL, 0);
1246 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001247 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Len Brown4be44fc2005-08-05 00:44:28 -04001249 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
1251 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001252 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
Patrick Mocheld550d982006-06-27 00:41:40 -04001254 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255}
1256
Len Brown4be44fc2005-08-05 00:44:28 -04001257static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Matthew Garrett01195092008-01-17 03:39:36 +00001259 long device_id;
1260 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001261 struct proc_dir_entry *entry = NULL;
1262 struct acpi_video_bus *video;
Matthew Garrett01195092008-01-17 03:39:36 +00001263 struct device *dev;
1264
1265 status =
1266 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1267
1268 if (!ACPI_SUCCESS(status))
1269 return -ENODEV;
1270
1271 /* We need to attempt to determine whether the _ADR refers to a
1272 PCI device or not. There's no terribly good way to do this,
1273 so the best we can hope for is to assume that there'll never
1274 be a video device in the host bridge */
1275 if (device_id >= 0x10000) {
1276 /* It looks like a PCI device. Does it exist? */
1277 dev = acpi_get_physical_device(device->handle);
1278 } else {
1279 /* It doesn't look like a PCI device. Does its parent
1280 exist? */
1281 acpi_handle phandle;
1282 if (acpi_get_parent(device->handle, &phandle))
1283 return -ENODEV;
1284 dev = acpi_get_physical_device(phandle);
1285 }
1286 if (!dev)
1287 return -ENODEV;
1288 put_device(dev);
1289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001292 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 if (!acpi_device_dir(device)) {
1295 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001296 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001298 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 video->dir = acpi_device_dir(device);
1300 acpi_device_dir(device)->owner = THIS_MODULE;
1301 }
1302
1303 /* 'info' [R] */
1304 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1305 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001306 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 else {
1308 entry->proc_fops = &acpi_video_bus_info_fops;
1309 entry->data = acpi_driver_data(device);
1310 entry->owner = THIS_MODULE;
1311 }
1312
1313 /* 'ROM' [R] */
1314 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1315 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001316 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 else {
1318 entry->proc_fops = &acpi_video_bus_ROM_fops;
1319 entry->data = acpi_driver_data(device);
1320 entry->owner = THIS_MODULE;
1321 }
1322
1323 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001324 entry =
1325 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001327 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 else {
1329 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1330 entry->data = acpi_driver_data(device);
1331 entry->owner = THIS_MODULE;
1332 }
1333
1334 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001335 entry =
1336 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1337 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001339 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001341 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 entry->data = acpi_driver_data(device);
1344 entry->owner = THIS_MODULE;
1345 }
1346
1347 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001348 entry =
1349 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1350 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001352 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001354 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 entry->data = acpi_driver_data(device);
1357 entry->owner = THIS_MODULE;
1358 }
1359
Patrick Mocheld550d982006-06-27 00:41:40 -04001360 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361}
1362
Len Brown4be44fc2005-08-05 00:44:28 -04001363static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364{
Len Brown4be44fc2005-08-05 00:44:28 -04001365 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001368 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
1370 if (acpi_device_dir(device)) {
1371 remove_proc_entry("info", acpi_device_dir(device));
1372 remove_proc_entry("ROM", acpi_device_dir(device));
1373 remove_proc_entry("POST_info", acpi_device_dir(device));
1374 remove_proc_entry("POST", acpi_device_dir(device));
1375 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001376 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 acpi_device_dir(device) = NULL;
1378 }
1379
Patrick Mocheld550d982006-06-27 00:41:40 -04001380 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381}
1382
1383/* --------------------------------------------------------------------------
1384 Driver Interface
1385 -------------------------------------------------------------------------- */
1386
1387/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001388static struct acpi_video_device_attrib*
1389acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1390{
1391 int count;
1392
1393 for(count = 0; count < video->attached_count; count++)
1394 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1395 return &(video->attached_array[count].value.attrib);
1396 return NULL;
1397}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
1399static int
Len Brown4be44fc2005-08-05 00:44:28 -04001400acpi_video_bus_get_one_device(struct acpi_device *device,
1401 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
Len Brown4be44fc2005-08-05 00:44:28 -04001403 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001404 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001405 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001406 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
1408 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001409 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
Len Brown4be44fc2005-08-05 00:44:28 -04001411 status =
1412 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 if (ACPI_SUCCESS(status)) {
1414
Burman Yan36bcbec2006-12-19 12:56:11 -08001415 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001417 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1420 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1421 acpi_driver_data(device) = data;
1422
1423 data->device_id = device_id;
1424 data->video = video;
1425 data->dev = device;
1426
Rui Zhang82cae992007-01-03 23:40:53 -05001427 attribute = acpi_video_get_device_attr(video, device_id);
1428
1429 if((attribute != NULL) && attribute->device_id_scheme) {
1430 switch (attribute->display_type) {
1431 case ACPI_VIDEO_DISPLAY_CRT:
1432 data->flags.crt = 1;
1433 break;
1434 case ACPI_VIDEO_DISPLAY_TV:
1435 data->flags.tvout = 1;
1436 break;
1437 case ACPI_VIDEO_DISPLAY_DVI:
1438 data->flags.dvi = 1;
1439 break;
1440 case ACPI_VIDEO_DISPLAY_LCD:
1441 data->flags.lcd = 1;
1442 break;
1443 default:
1444 data->flags.unknown = 1;
1445 break;
1446 }
1447 if(attribute->bios_can_detect)
1448 data->flags.bios = 1;
1449 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001451
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 acpi_video_device_bind(video, data);
1453 acpi_video_device_find_cap(data);
1454
Patrick Mochel90130262006-05-19 16:54:48 -04001455 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001456 ACPI_DEVICE_NOTIFY,
1457 acpi_video_device_notify,
1458 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 if (ACPI_FAILURE(status)) {
1460 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001461 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001462 if(data->brightness)
1463 kfree(data->brightness->levels);
1464 kfree(data->brightness);
1465 kfree(data);
1466 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 }
1468
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001469 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001471 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473 acpi_video_device_add_fs(device);
1474
Patrick Mocheld550d982006-06-27 00:41:40 -04001475 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 }
1477
Patrick Mocheld550d982006-06-27 00:41:40 -04001478 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
1481/*
1482 * Arg:
1483 * video : video bus device
1484 *
1485 * Return:
1486 * none
1487 *
1488 * Enumerate the video device list of the video bus,
1489 * bind the ids with the corresponding video devices
1490 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001491 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Len Brown4be44fc2005-08-05 00:44:28 -04001493static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001495 struct acpi_video_device *dev;
1496
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001497 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001498
1499 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001500 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001501
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001502 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
1505/*
1506 * Arg:
1507 * video : video bus device
1508 * device : video output device under the video
1509 * bus
1510 *
1511 * Return:
1512 * none
1513 *
1514 * Bind the ids with the corresponding video devices
1515 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001516 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518static void
Len Brown4be44fc2005-08-05 00:44:28 -04001519acpi_video_device_bind(struct acpi_video_bus *video,
1520 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Len Brown4be44fc2005-08-05 00:44:28 -04001522 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524#define IDS_VAL(i) video->attached_array[i].value.int_val
1525#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001526
1527 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1528 i < video->attached_count; i++) {
1529 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 IDS_BIND(i) = device;
1531 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1532 }
1533 }
1534#undef IDS_VAL
1535#undef IDS_BIND
1536}
1537
1538/*
1539 * Arg:
1540 * video : video bus device
1541 *
1542 * Return:
1543 * < 0 : error
1544 *
1545 * Call _DOD to enumerate all devices attached to display adapter
1546 *
Len Brown4be44fc2005-08-05 00:44:28 -04001547 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1550{
Len Brown4be44fc2005-08-05 00:44:28 -04001551 int status;
1552 int count;
1553 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001555 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1556 union acpi_object *dod = NULL;
1557 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Patrick Mochel90130262006-05-19 16:54:48 -04001559 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001561 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001562 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 }
1564
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001565 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001567 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 status = -EFAULT;
1569 goto out;
1570 }
1571
1572 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001573 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Len Brown4be44fc2005-08-05 00:44:28 -04001575 active_device_list = kmalloc((1 +
1576 dod->package.count) *
1577 sizeof(struct
1578 acpi_video_enumerated_device),
1579 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
1581 if (!active_device_list) {
1582 status = -ENOMEM;
1583 goto out;
1584 }
1585
1586 count = 0;
1587 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001588 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
1590 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001591 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001592 active_device_list[i].value.int_val =
1593 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 }
1595 active_device_list[i].value.int_val = obj->integer.value;
1596 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001597 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1598 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 count++;
1600 }
1601 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1602
Jesper Juhl6044ec82005-11-07 01:01:32 -08001603 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 video->attached_array = active_device_list;
1606 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001607 out:
Len Brown02438d82006-06-30 03:19:10 -04001608 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001609 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610}
1611
1612/*
1613 * Arg:
1614 * video : video bus device
Julius Volz98fb8fe2007-02-20 16:38:40 +01001615 * event : notify event
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 *
1617 * Return:
1618 * < 0 : error
1619 *
1620 * 1. Find out the current active output device.
Julius Volz98fb8fe2007-02-20 16:38:40 +01001621 * 2. Identify the next output device to switch to.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 * 3. call _DSS to do actual switch.
Len Brown4be44fc2005-08-05 00:44:28 -04001623 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Len Brown4be44fc2005-08-05 00:44:28 -04001625static int acpi_video_switch_output(struct acpi_video_bus *video, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001627 struct list_head *node;
Len Brown4be44fc2005-08-05 00:44:28 -04001628 struct acpi_video_device *dev = NULL;
1629 struct acpi_video_device *dev_next = NULL;
1630 struct acpi_video_device *dev_prev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 unsigned long state;
1632 int status = 0;
1633
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001634 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001636 list_for_each(node, &video->video_device_list) {
Adrian Bunk73345712005-03-30 22:31:35 -05001637 dev = container_of(node, struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 status = acpi_video_device_get_state(dev, &state);
Len Brown4be44fc2005-08-05 00:44:28 -04001639 if (state & 0x2) {
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001640 dev_next = container_of(node->next,
1641 struct acpi_video_device, entry);
1642 dev_prev = container_of(node->prev,
1643 struct acpi_video_device, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 goto out;
1645 }
1646 }
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 dev_next = container_of(node->next, struct acpi_video_device, entry);
1649 dev_prev = container_of(node->prev, struct acpi_video_device, entry);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001650
1651 out:
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001652 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 switch (event) {
1655 case ACPI_VIDEO_NOTIFY_CYCLE:
1656 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT:
1657 acpi_video_device_set_state(dev, 0);
1658 acpi_video_device_set_state(dev_next, 0x80000001);
1659 break;
1660 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT:
1661 acpi_video_device_set_state(dev, 0);
1662 acpi_video_device_set_state(dev_prev, 0x80000001);
1663 default:
1664 break;
1665 }
1666
Patrick Mocheld550d982006-06-27 00:41:40 -04001667 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Len Brown4be44fc2005-08-05 00:44:28 -04001670static int
1671acpi_video_get_next_level(struct acpi_video_device *device,
1672 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001674 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001675 max = max_below = 0;
1676 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001677 /* Find closest level to level_current */
1678 for (i = 0; i < device->brightness->count; i++) {
1679 l = device->brightness->levels[i];
1680 if (abs(l - level_current) < abs(delta)) {
1681 delta = l - level_current;
1682 if (!delta)
1683 break;
1684 }
1685 }
1686 /* Ajust level_current to closest available level */
1687 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001688 for (i = 0; i < device->brightness->count; i++) {
1689 l = device->brightness->levels[i];
1690 if (l < min)
1691 min = l;
1692 if (l > max)
1693 max = l;
1694 if (l < min_above && l > level_current)
1695 min_above = l;
1696 if (l > max_below && l < level_current)
1697 max_below = l;
1698 }
1699
1700 switch (event) {
1701 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1702 return (level_current < max) ? min_above : min;
1703 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1704 return (level_current < max) ? min_above : max;
1705 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1706 return (level_current > min) ? max_below : min;
1707 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1708 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1709 return 0;
1710 default:
1711 return level_current;
1712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715static void
Len Brown4be44fc2005-08-05 00:44:28 -04001716acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
1718 unsigned long level_current, level_next;
1719 acpi_video_device_lcd_get_level_current(device, &level_current);
1720 level_next = acpi_video_get_next_level(device, level_current, event);
1721 acpi_video_device_lcd_set_level(device, level_next);
1722}
1723
1724static int
Len Brown4be44fc2005-08-05 00:44:28 -04001725acpi_video_bus_get_devices(struct acpi_video_bus *video,
1726 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727{
Len Brown4be44fc2005-08-05 00:44:28 -04001728 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001729 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
1731 acpi_video_device_enumerate(video);
1732
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001733 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 status = acpi_video_bus_get_one_device(dev, video);
1736 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001737 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 continue;
1739 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001741 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
1743
Len Brown4be44fc2005-08-05 00:44:28 -04001744static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745{
Karol Kozimor031ec772005-07-30 04:18:00 -04001746 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 struct acpi_video_bus *video;
1748
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001751 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 video = device->video;
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 acpi_video_device_remove_fs(device->dev);
1756
Patrick Mochel90130262006-05-19 16:54:48 -04001757 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001758 ACPI_DEVICE_NOTIFY,
1759 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001760 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001761 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001762
Patrick Mocheld550d982006-06-27 00:41:40 -04001763 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764}
1765
Len Brown4be44fc2005-08-05 00:44:28 -04001766static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767{
Len Brown4be44fc2005-08-05 00:44:28 -04001768 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001769 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001771 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001773 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001775 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001776 if (ACPI_FAILURE(status))
1777 printk(KERN_WARNING PREFIX
1778 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001780 if (dev->brightness) {
1781 kfree(dev->brightness->levels);
1782 kfree(dev->brightness);
1783 }
1784 list_del(&dev->entry);
1785 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 }
1787
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001788 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001789
Patrick Mocheld550d982006-06-27 00:41:40 -04001790 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791}
1792
1793/* acpi_video interface */
1794
Len Brown4be44fc2005-08-05 00:44:28 -04001795static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796{
Zhang Ruia21101c2007-09-14 11:46:22 +08001797 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798}
1799
Len Brown4be44fc2005-08-05 00:44:28 -04001800static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
1802 return acpi_video_bus_DOS(video, 0, 1);
1803}
1804
Len Brown4be44fc2005-08-05 00:44:28 -04001805static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001807 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001808 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001809 struct input_dev *input;
1810 int keycode;
1811
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001813 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001815 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001816 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
1818 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001819 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001821 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001822 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 break;
1824
Julius Volz98fb8fe2007-02-20 16:38:40 +01001825 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 * connector. */
1827 acpi_video_device_enumerate(video);
1828 acpi_video_device_rebind(video);
1829 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001830 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001831 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 break;
1833
Len Brown4be44fc2005-08-05 00:44:28 -04001834 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001835 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001836 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001837 keycode = KEY_SWITCHVIDEOMODE;
1838 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001839 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Luming Yue9dab192007-08-20 18:23:53 +08001840 acpi_video_switch_output(video, event);
Len Brown25c87f72007-08-25 01:44:01 -04001841 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001842 keycode = KEY_VIDEO_NEXT;
1843 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001844 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 acpi_video_switch_output(video, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001846 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001847 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 break;
1849
1850 default:
Luming Yue9dab192007-08-20 18:23:53 +08001851 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001853 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 break;
1855 }
1856
Luming Yue9dab192007-08-20 18:23:53 +08001857 input_report_key(input, keycode, 1);
1858 input_sync(input);
1859 input_report_key(input, keycode, 0);
1860 input_sync(input);
1861
Patrick Mocheld550d982006-06-27 00:41:40 -04001862 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863}
1864
Len Brown4be44fc2005-08-05 00:44:28 -04001865static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001867 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001868 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001869 struct acpi_video_bus *bus;
1870 struct input_dev *input;
1871 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001874 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001876 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001877 bus = video_device->video;
1878 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
1880 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001881 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001882 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001883 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001884 keycode = KEY_BRIGHTNESS_CYCLE;
1885 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001886 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001887 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001888 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001889 keycode = KEY_BRIGHTNESSUP;
1890 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001891 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Luming Yue9dab192007-08-20 18:23:53 +08001892 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001893 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001894 keycode = KEY_BRIGHTNESSDOWN;
1895 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001896 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Luming Yue9dab192007-08-20 18:23:53 +08001897 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001898 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001899 keycode = KEY_BRIGHTNESS_ZERO;
1900 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001901 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
1902 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001903 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001904 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 break;
1906 default:
Luming Yue9dab192007-08-20 18:23:53 +08001907 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001909 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 break;
1911 }
Luming Yue9dab192007-08-20 18:23:53 +08001912
1913 input_report_key(input, keycode, 1);
1914 input_sync(input);
1915 input_report_key(input, keycode, 0);
1916 input_sync(input);
1917
Patrick Mocheld550d982006-06-27 00:41:40 -04001918 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
Zhang Ruie6d9da12007-08-25 02:23:31 -04001921static int instance;
Len Brown4be44fc2005-08-05 00:44:28 -04001922static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001924 acpi_status status;
1925 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001926 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001927 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
Burman Yan36bcbec2006-12-19 12:56:11 -08001929 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001931 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Zhang Ruie6d9da12007-08-25 02:23:31 -04001933 /* a hack to fix the duplicate name "VID" problem on T61 */
1934 if (!strcmp(device->pnp.bus_id, "VID")) {
1935 if (instance)
1936 device->pnp.bus_id[3] = '0' + instance;
1937 instance ++;
1938 }
1939
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001940 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1942 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1943 acpi_driver_data(device) = video;
1944
1945 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001946 error = acpi_video_bus_check(video);
1947 if (error)
1948 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001950 error = acpi_video_bus_add_fs(device);
1951 if (error)
1952 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001954 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 INIT_LIST_HEAD(&video->video_device_list);
1956
1957 acpi_video_bus_get_devices(video, device);
1958 acpi_video_bus_start_devices(video);
1959
Patrick Mochel90130262006-05-19 16:54:48 -04001960 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001961 ACPI_DEVICE_NOTIFY,
1962 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 if (ACPI_FAILURE(status)) {
1964 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001965 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001966 error = -ENODEV;
1967 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 }
1969
Luming Yue9dab192007-08-20 18:23:53 +08001970 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001971 if (!input) {
1972 error = -ENOMEM;
1973 goto err_uninstall_notify;
1974 }
Luming Yue9dab192007-08-20 18:23:53 +08001975
1976 snprintf(video->phys, sizeof(video->phys),
1977 "%s/video/input0", acpi_device_hid(video->device));
1978
1979 input->name = acpi_device_name(video->device);
1980 input->phys = video->phys;
1981 input->id.bustype = BUS_HOST;
1982 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05001983 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001984 input->evbit[0] = BIT(EV_KEY);
1985 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1986 set_bit(KEY_VIDEO_NEXT, input->keybit);
1987 set_bit(KEY_VIDEO_PREV, input->keybit);
1988 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1989 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1990 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1991 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1992 set_bit(KEY_DISPLAY_OFF, input->keybit);
1993 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08001994
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001995 error = input_register_device(input);
1996 if (error)
1997 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08001998
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04002000 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
2001 video->flags.multihead ? "yes" : "no",
2002 video->flags.rom ? "yes" : "no",
2003 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002005 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05002007 err_free_input_dev:
2008 input_free_device(input);
2009 err_uninstall_notify:
2010 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
2011 acpi_video_bus_notify);
2012 err_stop_video:
2013 acpi_video_bus_stop_devices(video);
2014 acpi_video_bus_put_devices(video);
2015 kfree(video->attached_array);
2016 acpi_video_bus_remove_fs(device);
2017 err_free_video:
2018 kfree(video);
2019 acpi_driver_data(device) = NULL;
2020
2021 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022}
2023
Len Brown4be44fc2005-08-05 00:44:28 -04002024static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025{
Len Brown4be44fc2005-08-05 00:44:28 -04002026 acpi_status status = 0;
2027 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04002031 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002033 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035 acpi_video_bus_stop_devices(video);
2036
Patrick Mochel90130262006-05-19 16:54:48 -04002037 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002038 ACPI_DEVICE_NOTIFY,
2039 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 acpi_video_bus_put_devices(video);
2042 acpi_video_bus_remove_fs(device);
2043
Luming Yue9dab192007-08-20 18:23:53 +08002044 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002045 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 kfree(video);
2047
Patrick Mocheld550d982006-06-27 00:41:40 -04002048 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
Len Brown4be44fc2005-08-05 00:44:28 -04002051static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052{
Len Brown4be44fc2005-08-05 00:44:28 -04002053 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
2056 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002057 acpi_dbg_level = 0xFFFFFFFF;
2058 acpi_dbg_layer = 0x08000000;
2059 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2062 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002063 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 acpi_video_dir->owner = THIS_MODULE;
2065
2066 result = acpi_bus_register_driver(&acpi_video_bus);
2067 if (result < 0) {
2068 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002069 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 }
2071
Patrick Mocheld550d982006-06-27 00:41:40 -04002072 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073}
2074
Len Brown4be44fc2005-08-05 00:44:28 -04002075static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
2078 acpi_bus_unregister_driver(&acpi_video_bus);
2079
2080 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2081
Patrick Mocheld550d982006-06-27 00:41:40 -04002082 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083}
2084
2085module_init(acpi_video_init);
2086module_exit(acpi_video_exit);