blob: 970c01a7f8f4437fe2378234803523026e99709c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * video.c - ACPI Video Driver ($Revision:$)
3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
Thomas Tuttlef4715182006-12-19 12:56:14 -08006 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
23 *
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25 */
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/init.h>
30#include <linux/types.h>
31#include <linux/list.h>
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -050032#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/proc_fs.h>
34#include <linux/seq_file.h>
Luming Yue9dab192007-08-20 18:23:53 +080035#include <linux/input.h>
Yu Luming2f3d0002006-11-11 02:40:34 +080036#include <linux/backlight.h>
Luming Yu23b0f012007-05-09 21:07:05 +080037#include <linux/video_output.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <asm/uaccess.h>
39
40#include <acpi/acpi_bus.h>
41#include <acpi/acpi_drivers.h>
42
43#define ACPI_VIDEO_COMPONENT 0x08000000
44#define ACPI_VIDEO_CLASS "video"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define ACPI_VIDEO_BUS_NAME "Video Bus"
46#define ACPI_VIDEO_DEVICE_NAME "Video Device"
47#define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48#define ACPI_VIDEO_NOTIFY_PROBE 0x81
49#define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
52
Thomas Tuttlef4715182006-12-19 12:56:14 -080053#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
60#define ACPI_VIDEO_HEAD_END (~0u)
Yu Luming2f3d0002006-11-11 02:40:34 +080061#define MAX_NAME_LEN 20
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Rui Zhang82cae992007-01-03 23:40:53 -050063#define ACPI_VIDEO_DISPLAY_CRT 1
64#define ACPI_VIDEO_DISPLAY_TV 2
65#define ACPI_VIDEO_DISPLAY_DVI 3
66#define ACPI_VIDEO_DISPLAY_LCD 4
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define _COMPONENT ACPI_VIDEO_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050069ACPI_MODULE_NAME("video");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Len Brownf52fd662007-02-12 22:42:12 -050071MODULE_AUTHOR("Bruno Ducrot");
Len Brown7cda93e2007-02-12 23:50:02 -050072MODULE_DESCRIPTION("ACPI Video Driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073MODULE_LICENSE("GPL");
74
Zhang Rui8a681a42008-01-25 14:47:49 +080075static int brightness_switch_enabled = 1;
76module_param(brightness_switch_enabled, bool, 0644);
77
Len Brown4be44fc2005-08-05 00:44:28 -040078static int acpi_video_bus_add(struct acpi_device *device);
79static int acpi_video_bus_remove(struct acpi_device *device, int type);
Matthew Garrett863c1492008-02-04 23:31:24 -080080static int acpi_video_resume(struct acpi_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Thomas Renninger1ba90e32007-07-23 14:44:41 +020082static const struct acpi_device_id video_device_ids[] = {
83 {ACPI_VIDEO_HID, 0},
84 {"", 0},
85};
86MODULE_DEVICE_TABLE(acpi, video_device_ids);
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static struct acpi_driver acpi_video_bus = {
Len Brownc2b67052007-02-12 23:33:40 -050089 .name = "video",
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 .class = ACPI_VIDEO_CLASS,
Thomas Renninger1ba90e32007-07-23 14:44:41 +020091 .ids = video_device_ids,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 .ops = {
93 .add = acpi_video_bus_add,
94 .remove = acpi_video_bus_remove,
Matthew Garrett863c1492008-02-04 23:31:24 -080095 .resume = acpi_video_resume,
Len Brown4be44fc2005-08-05 00:44:28 -040096 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99struct acpi_video_bus_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400100 u8 multihead:1; /* can switch video heads */
101 u8 rom:1; /* can retrieve a video rom */
102 u8 post:1; /* can configure the head to */
103 u8 reserved:5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104};
105
106struct acpi_video_bus_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400107 u8 _DOS:1; /*Enable/Disable output switching */
108 u8 _DOD:1; /*Enumerate all devices attached to display adapter */
109 u8 _ROM:1; /*Get ROM Data */
110 u8 _GPD:1; /*Get POST Device */
111 u8 _SPD:1; /*Set POST Device */
112 u8 _VPO:1; /*Video POST Options */
113 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114};
115
Len Brown4be44fc2005-08-05 00:44:28 -0400116struct acpi_video_device_attrib {
117 u32 display_index:4; /* A zero-based instance of the Display */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100118 u32 display_port_attachment:4; /*This field differentiates the display type */
Len Brown4be44fc2005-08-05 00:44:28 -0400119 u32 display_type:4; /*Describe the specific type in use */
Julius Volz98fb8fe2007-02-20 16:38:40 +0100120 u32 vendor_specific:4; /*Chipset Vendor Specific */
Len Brown4be44fc2005-08-05 00:44:28 -0400121 u32 bios_can_detect:1; /*BIOS can detect the device */
122 u32 depend_on_vga:1; /*Non-VGA output device whose power is related to
123 the VGA device. */
124 u32 pipe_id:3; /*For VGA multiple-head devices. */
125 u32 reserved:10; /*Must be 0 */
126 u32 device_id_scheme:1; /*Device ID Scheme */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127};
128
129struct acpi_video_enumerated_device {
130 union {
131 u32 int_val;
Len Brown4be44fc2005-08-05 00:44:28 -0400132 struct acpi_video_device_attrib attrib;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 } value;
134 struct acpi_video_device *bind_info;
135};
136
137struct acpi_video_bus {
Patrick Mochele6afa0d2006-05-19 16:54:40 -0400138 struct acpi_device *device;
Len Brown4be44fc2005-08-05 00:44:28 -0400139 u8 dos_setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 struct acpi_video_enumerated_device *attached_array;
Len Brown4be44fc2005-08-05 00:44:28 -0400141 u8 attached_count;
142 struct acpi_video_bus_cap cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 struct acpi_video_bus_flags flags;
Len Brown4be44fc2005-08-05 00:44:28 -0400144 struct list_head video_device_list;
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -0500145 struct mutex device_list_lock; /* protects video_device_list */
Len Brown4be44fc2005-08-05 00:44:28 -0400146 struct proc_dir_entry *dir;
Luming Yue9dab192007-08-20 18:23:53 +0800147 struct input_dev *input;
148 char phys[32]; /* for input device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
151struct acpi_video_device_flags {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 u8 crt:1;
153 u8 lcd:1;
154 u8 tvout:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500155 u8 dvi:1;
Len Brown4be44fc2005-08-05 00:44:28 -0400156 u8 bios:1;
157 u8 unknown:1;
Rui Zhang82cae992007-01-03 23:40:53 -0500158 u8 reserved:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
161struct acpi_video_device_cap {
Len Brown4be44fc2005-08-05 00:44:28 -0400162 u8 _ADR:1; /*Return the unique ID */
163 u8 _BCL:1; /*Query list of brightness control levels supported */
164 u8 _BCM:1; /*Set the brightness level */
Yu Luming2f3d0002006-11-11 02:40:34 +0800165 u8 _BQC:1; /* Get current brightness level */
Len Brown4be44fc2005-08-05 00:44:28 -0400166 u8 _DDC:1; /*Return the EDID for this device */
167 u8 _DCS:1; /*Return status of output device */
168 u8 _DGS:1; /*Query graphics state */
169 u8 _DSS:1; /*Device state set */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170};
171
172struct acpi_video_device_brightness {
Len Brown4be44fc2005-08-05 00:44:28 -0400173 int curr;
174 int count;
175 int *levels;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176};
177
178struct acpi_video_device {
Len Brown4be44fc2005-08-05 00:44:28 -0400179 unsigned long device_id;
180 struct acpi_video_device_flags flags;
181 struct acpi_video_device_cap cap;
182 struct list_head entry;
183 struct acpi_video_bus *video;
184 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 struct acpi_video_device_brightness *brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800186 struct backlight_device *backlight;
Luming Yu23b0f012007-05-09 21:07:05 +0800187 struct output_device *output_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188};
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* bus */
191static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file);
192static struct file_operations acpi_video_bus_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400193 .open = acpi_video_bus_info_open_fs,
194 .read = seq_read,
195 .llseek = seq_lseek,
196 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197};
198
199static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file);
200static struct file_operations acpi_video_bus_ROM_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400201 .open = acpi_video_bus_ROM_open_fs,
202 .read = seq_read,
203 .llseek = seq_lseek,
204 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205};
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207static int acpi_video_bus_POST_info_open_fs(struct inode *inode,
208 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static struct file_operations acpi_video_bus_POST_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400210 .open = acpi_video_bus_POST_info_open_fs,
211 .read = seq_read,
212 .llseek = seq_lseek,
213 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
215
216static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file);
217static struct file_operations acpi_video_bus_POST_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 .open = acpi_video_bus_POST_open_fs,
219 .read = seq_read,
220 .llseek = seq_lseek,
221 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222};
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file);
225static struct file_operations acpi_video_bus_DOS_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400226 .open = acpi_video_bus_DOS_open_fs,
227 .read = seq_read,
228 .llseek = seq_lseek,
229 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230};
231
232/* device */
Len Brown4be44fc2005-08-05 00:44:28 -0400233static int acpi_video_device_info_open_fs(struct inode *inode,
234 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235static struct file_operations acpi_video_device_info_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400236 .open = acpi_video_device_info_open_fs,
237 .read = seq_read,
238 .llseek = seq_lseek,
239 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240};
241
Len Brown4be44fc2005-08-05 00:44:28 -0400242static int acpi_video_device_state_open_fs(struct inode *inode,
243 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244static struct file_operations acpi_video_device_state_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400245 .open = acpi_video_device_state_open_fs,
246 .read = seq_read,
247 .llseek = seq_lseek,
248 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249};
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251static int acpi_video_device_brightness_open_fs(struct inode *inode,
252 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static struct file_operations acpi_video_device_brightness_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400254 .open = acpi_video_device_brightness_open_fs,
255 .read = seq_read,
256 .llseek = seq_lseek,
257 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258};
259
Len Brown4be44fc2005-08-05 00:44:28 -0400260static int acpi_video_device_EDID_open_fs(struct inode *inode,
261 struct file *file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262static struct file_operations acpi_video_device_EDID_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -0400263 .open = acpi_video_device_EDID_open_fs,
264 .read = seq_read,
265 .llseek = seq_lseek,
266 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267};
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269static char device_decode[][30] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 "motherboard VGA device",
271 "PCI VGA device",
272 "AGP VGA device",
273 "UNKNOWN",
274};
275
Len Brown4be44fc2005-08-05 00:44:28 -0400276static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data);
277static void acpi_video_device_rebind(struct acpi_video_bus *video);
278static void acpi_video_device_bind(struct acpi_video_bus *video,
279 struct acpi_video_device *device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static int acpi_video_device_enumerate(struct acpi_video_bus *video);
Yu Luming2f3d0002006-11-11 02:40:34 +0800281static int acpi_video_device_lcd_set_level(struct acpi_video_device *device,
282 int level);
283static int acpi_video_device_lcd_get_level_current(
284 struct acpi_video_device *device,
285 unsigned long *level);
Len Brown4be44fc2005-08-05 00:44:28 -0400286static int acpi_video_get_next_level(struct acpi_video_device *device,
287 u32 level_current, u32 event);
288static void acpi_video_switch_brightness(struct acpi_video_device *device,
289 int event);
Luming Yu23b0f012007-05-09 21:07:05 +0800290static int acpi_video_device_get_state(struct acpi_video_device *device,
291 unsigned long *state);
292static int acpi_video_output_get(struct output_device *od);
293static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Yu Luming2f3d0002006-11-11 02:40:34 +0800295/*backlight device sysfs support*/
296static int acpi_video_get_brightness(struct backlight_device *bd)
297{
298 unsigned long cur_level;
299 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100300 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800301 acpi_video_device_lcd_get_level_current(vd, &cur_level);
302 return (int) cur_level;
303}
304
305static int acpi_video_set_brightness(struct backlight_device *bd)
306{
Richard Purdie599a52d2007-02-10 23:07:48 +0000307 int request_level = bd->props.brightness;
Yu Luming2f3d0002006-11-11 02:40:34 +0800308 struct acpi_video_device *vd =
Richard Purdie655bfd72007-07-09 12:17:24 +0100309 (struct acpi_video_device *)bl_get_data(bd);
Yu Luming2f3d0002006-11-11 02:40:34 +0800310 acpi_video_device_lcd_set_level(vd, request_level);
311 return 0;
312}
313
Richard Purdie599a52d2007-02-10 23:07:48 +0000314static struct backlight_ops acpi_backlight_ops = {
315 .get_brightness = acpi_video_get_brightness,
316 .update_status = acpi_video_set_brightness,
317};
318
Luming Yu23b0f012007-05-09 21:07:05 +0800319/*video output device sysfs support*/
320static int acpi_video_output_get(struct output_device *od)
321{
322 unsigned long state;
323 struct acpi_video_device *vd =
tonyj@suse.de60043422007-08-07 22:28:47 -0700324 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800325 acpi_video_device_get_state(vd, &state);
326 return (int)state;
327}
328
329static int acpi_video_output_set(struct output_device *od)
330{
331 unsigned long state = od->request_state;
332 struct acpi_video_device *vd=
tonyj@suse.de60043422007-08-07 22:28:47 -0700333 (struct acpi_video_device *)dev_get_drvdata(&od->dev);
Luming Yu23b0f012007-05-09 21:07:05 +0800334 return acpi_video_device_set_state(vd, state);
335}
336
337static struct output_properties acpi_output_properties = {
338 .set_state = acpi_video_output_set,
339 .get_status = acpi_video_output_get,
340};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/* --------------------------------------------------------------------------
342 Video Management
343 -------------------------------------------------------------------------- */
344
345/* device */
346
347static int
Len Brown4be44fc2005-08-05 00:44:28 -0400348acpi_video_device_query(struct acpi_video_device *device, unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Len Brown4be44fc2005-08-05 00:44:28 -0400350 int status;
Patrick Mochel90130262006-05-19 16:54:48 -0400351
352 status = acpi_evaluate_integer(device->dev->handle, "_DGS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Patrick Mocheld550d982006-06-27 00:41:40 -0400354 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
357static int
Len Brown4be44fc2005-08-05 00:44:28 -0400358acpi_video_device_get_state(struct acpi_video_device *device,
359 unsigned long *state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Len Brown4be44fc2005-08-05 00:44:28 -0400361 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Patrick Mochel90130262006-05-19 16:54:48 -0400363 status = acpi_evaluate_integer(device->dev->handle, "_DCS", NULL, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Patrick Mocheld550d982006-06-27 00:41:40 -0400365 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
368static int
Len Brown4be44fc2005-08-05 00:44:28 -0400369acpi_video_device_set_state(struct acpi_video_device *device, int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Len Brown4be44fc2005-08-05 00:44:28 -0400371 int status;
372 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
373 struct acpi_object_list args = { 1, &arg0 };
Luming Yu824b5582005-08-21 19:17:00 -0400374 unsigned long ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 arg0.integer.value = state;
Patrick Mochel90130262006-05-19 16:54:48 -0400378 status = acpi_evaluate_integer(device->dev->handle, "_DSS", &args, &ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Patrick Mocheld550d982006-06-27 00:41:40 -0400380 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
382
383static int
Len Brown4be44fc2005-08-05 00:44:28 -0400384acpi_video_device_lcd_query_levels(struct acpi_video_device *device,
385 union acpi_object **levels)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Len Brown4be44fc2005-08-05 00:44:28 -0400387 int status;
388 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
389 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 *levels = NULL;
393
Patrick Mochel90130262006-05-19 16:54:48 -0400394 status = acpi_evaluate_object(device->dev->handle, "_BCL", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400396 return status;
Len Brown4be44fc2005-08-05 00:44:28 -0400397 obj = (union acpi_object *)buffer.pointer;
Adrian Bunk6665bda2006-03-11 10:12:00 -0500398 if (!obj || (obj->type != ACPI_TYPE_PACKAGE)) {
Len Brown64684632006-06-26 23:41:38 -0400399 printk(KERN_ERR PREFIX "Invalid _BCL data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 status = -EFAULT;
401 goto err;
402 }
403
404 *levels = obj;
405
Patrick Mocheld550d982006-06-27 00:41:40 -0400406 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 err:
Jesper Juhl6044ec82005-11-07 01:01:32 -0800409 kfree(buffer.pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Patrick Mocheld550d982006-06-27 00:41:40 -0400411 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414static int
Len Brown4be44fc2005-08-05 00:44:28 -0400415acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400417 int status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400418 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
419 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 arg0.integer.value = level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400424 if (device->cap._BCM)
425 status = acpi_evaluate_object(device->dev->handle, "_BCM",
426 &args, NULL);
427 device->brightness->curr = level;
Patrick Mocheld550d982006-06-27 00:41:40 -0400428 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429}
430
431static int
Len Brown4be44fc2005-08-05 00:44:28 -0400432acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
433 unsigned long *level)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Alexey Starikovskiy4500ca82007-09-03 16:29:58 +0400435 if (device->cap._BQC)
436 return acpi_evaluate_integer(device->dev->handle, "_BQC", NULL,
437 level);
438 *level = device->brightness->curr;
439 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442static int
Len Brown4be44fc2005-08-05 00:44:28 -0400443acpi_video_device_EDID(struct acpi_video_device *device,
444 union acpi_object **edid, ssize_t length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Len Brown4be44fc2005-08-05 00:44:28 -0400446 int status;
447 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
448 union acpi_object *obj;
449 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
450 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 *edid = NULL;
454
455 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -0400456 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 if (length == 128)
458 arg0.integer.value = 1;
459 else if (length == 256)
460 arg0.integer.value = 2;
461 else
Patrick Mocheld550d982006-06-27 00:41:40 -0400462 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Patrick Mochel90130262006-05-19 16:54:48 -0400464 status = acpi_evaluate_object(device->dev->handle, "_DDC", &args, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 if (ACPI_FAILURE(status))
Patrick Mocheld550d982006-06-27 00:41:40 -0400466 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200468 obj = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 if (obj && obj->type == ACPI_TYPE_BUFFER)
471 *edid = obj;
472 else {
Len Brown64684632006-06-26 23:41:38 -0400473 printk(KERN_ERR PREFIX "Invalid _DDC data\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 status = -EFAULT;
475 kfree(obj);
476 }
477
Patrick Mocheld550d982006-06-27 00:41:40 -0400478 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479}
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481/* bus */
482
483static int
Len Brown4be44fc2005-08-05 00:44:28 -0400484acpi_video_bus_set_POST(struct acpi_video_bus *video, unsigned long option)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Len Brown4be44fc2005-08-05 00:44:28 -0400486 int status;
487 unsigned long tmp;
488 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
489 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 arg0.integer.value = option;
493
Patrick Mochel90130262006-05-19 16:54:48 -0400494 status = acpi_evaluate_integer(video->device->handle, "_SPD", &args, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (ACPI_SUCCESS(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400496 status = tmp ? (-EINVAL) : (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Patrick Mocheld550d982006-06-27 00:41:40 -0400498 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
501static int
Len Brown4be44fc2005-08-05 00:44:28 -0400502acpi_video_bus_get_POST(struct acpi_video_bus *video, unsigned long *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503{
504 int status;
505
Patrick Mochel90130262006-05-19 16:54:48 -0400506 status = acpi_evaluate_integer(video->device->handle, "_GPD", NULL, id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Patrick Mocheld550d982006-06-27 00:41:40 -0400508 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509}
510
511static int
Len Brown4be44fc2005-08-05 00:44:28 -0400512acpi_video_bus_POST_options(struct acpi_video_bus *video,
513 unsigned long *options)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
Len Brown4be44fc2005-08-05 00:44:28 -0400515 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Patrick Mochel90130262006-05-19 16:54:48 -0400517 status = acpi_evaluate_integer(video->device->handle, "_VPO", NULL, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 *options &= 3;
519
Patrick Mocheld550d982006-06-27 00:41:40 -0400520 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
523/*
524 * Arg:
525 * video : video bus device pointer
526 * bios_flag :
527 * 0. The system BIOS should NOT automatically switch(toggle)
528 * the active display output.
529 * 1. The system BIOS should automatically switch (toggle) the
Julius Volz98fb8fe2007-02-20 16:38:40 +0100530 * active display output. No switch event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 * 2. The _DGS value should be locked.
532 * 3. The system BIOS should not automatically switch (toggle) the
533 * active display output, but instead generate the display switch
534 * event notify code.
535 * lcd_flag :
536 * 0. The system BIOS should automatically control the brightness level
Julius Volz98fb8fe2007-02-20 16:38:40 +0100537 * of the LCD when the power changes from AC to DC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 * 1. The system BIOS should NOT automatically control the brightness
Julius Volz98fb8fe2007-02-20 16:38:40 +0100539 * level of the LCD when the power changes from AC to DC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 * Return Value:
541 * -1 wrong arg.
542 */
543
544static int
Len Brown4be44fc2005-08-05 00:44:28 -0400545acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
Len Brown4be44fc2005-08-05 00:44:28 -0400547 acpi_integer status = 0;
548 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
549 struct acpi_object_list args = { 1, &arg0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Len Brown4be44fc2005-08-05 00:44:28 -0400552 if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 status = -1;
554 goto Failed;
555 }
556 arg0.integer.value = (lcd_flag << 2) | bios_flag;
557 video->dos_setting = arg0.integer.value;
Patrick Mochel90130262006-05-19 16:54:48 -0400558 acpi_evaluate_object(video->device->handle, "_DOS", &args, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Len Brown4be44fc2005-08-05 00:44:28 -0400560 Failed:
Patrick Mocheld550d982006-06-27 00:41:40 -0400561 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
564/*
565 * Arg:
566 * device : video output device (LCD, CRT, ..)
567 *
568 * Return Value:
569 * None
570 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100571 * Find out all required AML methods defined under the output
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 * device.
573 */
574
Len Brown4be44fc2005-08-05 00:44:28 -0400575static void acpi_video_device_find_cap(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 acpi_handle h_dummy1;
578 int i;
Yu Luming2f3d0002006-11-11 02:40:34 +0800579 u32 max_level = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 union acpi_object *obj = NULL;
581 struct acpi_video_device_brightness *br = NULL;
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
William Lee Irwin III98934de2007-12-12 03:56:55 -0800584 memset(&device->cap, 0, sizeof(device->cap));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Patrick Mochel90130262006-05-19 16:54:48 -0400586 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_ADR", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 device->cap._ADR = 1;
588 }
Patrick Mochel90130262006-05-19 16:54:48 -0400589 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCL", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400590 device->cap._BCL = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 }
Patrick Mochel90130262006-05-19 16:54:48 -0400592 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_BCM", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400593 device->cap._BCM = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
Yu Luming2f3d0002006-11-11 02:40:34 +0800595 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle,"_BQC",&h_dummy1)))
596 device->cap._BQC = 1;
Patrick Mochel90130262006-05-19 16:54:48 -0400597 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DDC", &h_dummy1))) {
Len Brown4be44fc2005-08-05 00:44:28 -0400598 device->cap._DDC = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 }
Patrick Mochel90130262006-05-19 16:54:48 -0400600 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DCS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 device->cap._DCS = 1;
602 }
Patrick Mochel90130262006-05-19 16:54:48 -0400603 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DGS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 device->cap._DGS = 1;
605 }
Patrick Mochel90130262006-05-19 16:54:48 -0400606 if (ACPI_SUCCESS(acpi_get_handle(device->dev->handle, "_DSS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 device->cap._DSS = 1;
608 }
609
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400610 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400612 if (obj->package.count >= 2) {
613 int count = 0;
614 union acpi_object *o;
Len Brown4be44fc2005-08-05 00:44:28 -0400615
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400616 br = kzalloc(sizeof(*br), GFP_KERNEL);
617 if (!br) {
618 printk(KERN_ERR "can't allocate memory\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 } else {
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400620 br->levels = kmalloc(obj->package.count *
621 sizeof *(br->levels), GFP_KERNEL);
622 if (!br->levels)
623 goto out;
624
625 for (i = 0; i < obj->package.count; i++) {
626 o = (union acpi_object *)&obj->package.
627 elements[i];
628 if (o->type != ACPI_TYPE_INTEGER) {
629 printk(KERN_ERR PREFIX "Invalid data\n");
630 continue;
631 }
632 br->levels[count] = (u32) o->integer.value;
633
634 if (br->levels[count] > max_level)
635 max_level = br->levels[count];
636 count++;
637 }
638 out:
639 if (count < 2) {
640 kfree(br->levels);
641 kfree(br);
642 } else {
643 br->count = count;
644 device->brightness = br;
645 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
646 "found %d brightness levels\n",
647 count));
648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 }
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400651
652 } else {
653 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655
Paulo Marquesd1dd0c22005-03-30 22:39:49 -0500656 kfree(obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Danny Kukawkaf70ac0e2007-07-03 01:33:53 -0400658 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
Yu Luming2f3d0002006-11-11 02:40:34 +0800659 unsigned long tmp;
660 static int count = 0;
661 char *name;
Yu Luming2f3d0002006-11-11 02:40:34 +0800662 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
663 if (!name)
664 return;
665
Yu Luming2f3d0002006-11-11 02:40:34 +0800666 sprintf(name, "acpi_video%d", count++);
Yu Luming2f3d0002006-11-11 02:40:34 +0800667 acpi_video_device_lcd_get_level_current(device, &tmp);
Yu Luming2f3d0002006-11-11 02:40:34 +0800668 device->backlight = backlight_device_register(name,
Richard Purdie599a52d2007-02-10 23:07:48 +0000669 NULL, device, &acpi_backlight_ops);
670 device->backlight->props.max_brightness = max_level;
671 device->backlight->props.brightness = (int)tmp;
672 backlight_update_status(device->backlight);
673
Yu Luming2f3d0002006-11-11 02:40:34 +0800674 kfree(name);
675 }
Luming Yu23b0f012007-05-09 21:07:05 +0800676 if (device->cap._DCS && device->cap._DSS){
677 static int count = 0;
678 char *name;
679 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
680 if (!name)
681 return;
682 sprintf(name, "acpi_video%d", count++);
683 device->output_dev = video_output_register(name,
684 NULL, device, &acpi_output_properties);
685 kfree(name);
686 }
Patrick Mocheld550d982006-06-27 00:41:40 -0400687 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690/*
691 * Arg:
692 * device : video output device (VGA)
693 *
694 * Return Value:
695 * None
696 *
Julius Volz98fb8fe2007-02-20 16:38:40 +0100697 * Find out all required AML methods defined under the video bus device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 */
699
Len Brown4be44fc2005-08-05 00:44:28 -0400700static void acpi_video_bus_find_cap(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Len Brown4be44fc2005-08-05 00:44:28 -0400702 acpi_handle h_dummy1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
William Lee Irwin III98934de2007-12-12 03:56:55 -0800704 memset(&video->cap, 0, sizeof(video->cap));
Patrick Mochel90130262006-05-19 16:54:48 -0400705 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOS", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 video->cap._DOS = 1;
707 }
Patrick Mochel90130262006-05-19 16:54:48 -0400708 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_DOD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 video->cap._DOD = 1;
710 }
Patrick Mochel90130262006-05-19 16:54:48 -0400711 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_ROM", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 video->cap._ROM = 1;
713 }
Patrick Mochel90130262006-05-19 16:54:48 -0400714 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_GPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 video->cap._GPD = 1;
716 }
Patrick Mochel90130262006-05-19 16:54:48 -0400717 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_SPD", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 video->cap._SPD = 1;
719 }
Patrick Mochel90130262006-05-19 16:54:48 -0400720 if (ACPI_SUCCESS(acpi_get_handle(video->device->handle, "_VPO", &h_dummy1))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 video->cap._VPO = 1;
722 }
723}
724
725/*
726 * Check whether the video bus device has required AML method to
727 * support the desired features
728 */
729
Len Brown4be44fc2005-08-05 00:44:28 -0400730static int acpi_video_bus_check(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731{
Len Brown4be44fc2005-08-05 00:44:28 -0400732 acpi_status status = -ENOENT;
Matthew Garrett3fa2cdc2008-02-07 01:44:06 +0000733 long device_id;
734 struct device *dev;
735 struct acpi_device *device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -0400738 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Matthew Garrett3fa2cdc2008-02-07 01:44:06 +0000740 device = video->device;
741
742 status =
743 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
744
745 if (!ACPI_SUCCESS(status))
746 return -ENODEV;
747
748 /* We need to attempt to determine whether the _ADR refers to a
749 PCI device or not. There's no terribly good way to do this,
750 so the best we can hope for is to assume that there'll never
751 be a video device in the host bridge */
752 if (device_id >= 0x10000) {
753 /* It looks like a PCI device. Does it exist? */
754 dev = acpi_get_physical_device(device->handle);
755 } else {
756 /* It doesn't look like a PCI device. Does its parent
757 exist? */
758 acpi_handle phandle;
759 if (acpi_get_parent(device->handle, &phandle))
760 return -ENODEV;
761 dev = acpi_get_physical_device(phandle);
762 }
763 if (!dev)
764 return -ENODEV;
765 put_device(dev);
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 /* Since there is no HID, CID and so on for VGA driver, we have
768 * to check well known required nodes.
769 */
770
Julius Volz98fb8fe2007-02-20 16:38:40 +0100771 /* Does this device support video switching? */
Len Brown4be44fc2005-08-05 00:44:28 -0400772 if (video->cap._DOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 video->flags.multihead = 1;
774 status = 0;
775 }
776
Julius Volz98fb8fe2007-02-20 16:38:40 +0100777 /* Does this device support retrieving a video ROM? */
Len Brown4be44fc2005-08-05 00:44:28 -0400778 if (video->cap._ROM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 video->flags.rom = 1;
780 status = 0;
781 }
782
Julius Volz98fb8fe2007-02-20 16:38:40 +0100783 /* Does this device support configuring which video device to POST? */
Len Brown4be44fc2005-08-05 00:44:28 -0400784 if (video->cap._GPD && video->cap._SPD && video->cap._VPO) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 video->flags.post = 1;
786 status = 0;
787 }
788
Patrick Mocheld550d982006-06-27 00:41:40 -0400789 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
791
792/* --------------------------------------------------------------------------
793 FS Interface (/proc)
794 -------------------------------------------------------------------------- */
795
Len Brown4be44fc2005-08-05 00:44:28 -0400796static struct proc_dir_entry *acpi_video_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798/* video devices */
799
Len Brown4be44fc2005-08-05 00:44:28 -0400800static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200802 struct acpi_video_device *dev = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 if (!dev)
806 goto end;
807
808 seq_printf(seq, "device_id: 0x%04x\n", (u32) dev->device_id);
809 seq_printf(seq, "type: ");
810 if (dev->flags.crt)
811 seq_printf(seq, "CRT\n");
812 else if (dev->flags.lcd)
813 seq_printf(seq, "LCD\n");
814 else if (dev->flags.tvout)
815 seq_printf(seq, "TVOUT\n");
Rui Zhang82cae992007-01-03 23:40:53 -0500816 else if (dev->flags.dvi)
817 seq_printf(seq, "DVI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 else
819 seq_printf(seq, "UNKNOWN\n");
820
Len Brown4be44fc2005-08-05 00:44:28 -0400821 seq_printf(seq, "known by bios: %s\n", dev->flags.bios ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
Len Brown4be44fc2005-08-05 00:44:28 -0400823 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400824 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
827static int
Len Brown4be44fc2005-08-05 00:44:28 -0400828acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
830 return single_open(file, acpi_video_device_info_seq_show,
831 PDE(inode)->data);
832}
833
Len Brown4be44fc2005-08-05 00:44:28 -0400834static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835{
Len Brown4be44fc2005-08-05 00:44:28 -0400836 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200837 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400838 unsigned long state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 if (!dev)
842 goto end;
843
844 status = acpi_video_device_get_state(dev, &state);
845 seq_printf(seq, "state: ");
846 if (ACPI_SUCCESS(status))
847 seq_printf(seq, "0x%02lx\n", state);
848 else
849 seq_printf(seq, "<not supported>\n");
850
851 status = acpi_video_device_query(dev, &state);
852 seq_printf(seq, "query: ");
853 if (ACPI_SUCCESS(status))
854 seq_printf(seq, "0x%02lx\n", state);
855 else
856 seq_printf(seq, "<not supported>\n");
857
Len Brown4be44fc2005-08-05 00:44:28 -0400858 end:
Patrick Mocheld550d982006-06-27 00:41:40 -0400859 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860}
861
862static int
Len Brown4be44fc2005-08-05 00:44:28 -0400863acpi_video_device_state_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864{
865 return single_open(file, acpi_video_device_state_seq_show,
866 PDE(inode)->data);
867}
868
869static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400870acpi_video_device_write_state(struct file *file,
871 const char __user * buffer,
872 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Len Brown4be44fc2005-08-05 00:44:28 -0400874 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200875 struct seq_file *m = file->private_data;
876 struct acpi_video_device *dev = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400877 char str[12] = { 0 };
878 u32 state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 if (!dev || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400882 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
884 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400885 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 str[count] = 0;
888 state = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400889 state &= ((1ul << 31) | (1ul << 30) | (1ul << 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 status = acpi_video_device_set_state(dev, state);
892
893 if (status)
Patrick Mocheld550d982006-06-27 00:41:40 -0400894 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Patrick Mocheld550d982006-06-27 00:41:40 -0400896 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897}
898
899static int
Len Brown4be44fc2005-08-05 00:44:28 -0400900acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200902 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400903 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 if (!dev || !dev->brightness) {
907 seq_printf(seq, "<not supported>\n");
Patrick Mocheld550d982006-06-27 00:41:40 -0400908 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910
911 seq_printf(seq, "levels: ");
912 for (i = 0; i < dev->brightness->count; i++)
913 seq_printf(seq, " %d", dev->brightness->levels[i]);
914 seq_printf(seq, "\ncurrent: %d\n", dev->brightness->curr);
915
Patrick Mocheld550d982006-06-27 00:41:40 -0400916 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917}
918
919static int
Len Brown4be44fc2005-08-05 00:44:28 -0400920acpi_video_device_brightness_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921{
922 return single_open(file, acpi_video_device_brightness_seq_show,
923 PDE(inode)->data);
924}
925
926static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -0400927acpi_video_device_write_brightness(struct file *file,
928 const char __user * buffer,
929 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200931 struct seq_file *m = file->private_data;
932 struct acpi_video_device *dev = m->private;
Danny Baumannc88c5782007-11-02 13:47:53 +0100933 char str[5] = { 0 };
Len Brown4be44fc2005-08-05 00:44:28 -0400934 unsigned int level = 0;
935 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
Thomas Renninger59d399d2005-11-08 05:27:00 -0500938 if (!dev || !dev->brightness || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -0400939 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -0400942 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 str[count] = 0;
945 level = simple_strtoul(str, NULL, 0);
Len Brown4be44fc2005-08-05 00:44:28 -0400946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if (level > 100)
Patrick Mocheld550d982006-06-27 00:41:40 -0400948 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Julius Volz98fb8fe2007-02-20 16:38:40 +0100950 /* validate through the list of available levels */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 for (i = 0; i < dev->brightness->count; i++)
952 if (level == dev->brightness->levels[i]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400953 if (ACPI_SUCCESS
954 (acpi_video_device_lcd_set_level(dev, level)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 dev->brightness->curr = level;
956 break;
957 }
958
Patrick Mocheld550d982006-06-27 00:41:40 -0400959 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960}
961
Len Brown4be44fc2005-08-05 00:44:28 -0400962static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
Jan Engelhardt50dd0962006-10-01 00:28:50 +0200964 struct acpi_video_device *dev = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -0400965 int status;
966 int i;
967 union acpi_object *edid = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 if (!dev)
971 goto out;
972
Len Brown4be44fc2005-08-05 00:44:28 -0400973 status = acpi_video_device_EDID(dev, &edid, 128);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400975 status = acpi_video_device_EDID(dev, &edid, 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 }
977
978 if (ACPI_FAILURE(status)) {
979 goto out;
980 }
981
982 if (edid && edid->type == ACPI_TYPE_BUFFER) {
983 for (i = 0; i < edid->buffer.length; i++)
984 seq_putc(seq, edid->buffer.pointer[i]);
985 }
986
Len Brown4be44fc2005-08-05 00:44:28 -0400987 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 if (!edid)
989 seq_printf(seq, "<not supported>\n");
990 else
991 kfree(edid);
992
Patrick Mocheld550d982006-06-27 00:41:40 -0400993 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994}
995
996static int
Len Brown4be44fc2005-08-05 00:44:28 -0400997acpi_video_device_EDID_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998{
999 return single_open(file, acpi_video_device_EDID_seq_show,
1000 PDE(inode)->data);
1001}
1002
Len Brown4be44fc2005-08-05 00:44:28 -04001003static int acpi_video_device_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004{
Len Brown4be44fc2005-08-05 00:44:28 -04001005 struct proc_dir_entry *entry = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 struct acpi_video_device *vid_dev;
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 if (!device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001010 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001012 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (!vid_dev)
Patrick Mocheld550d982006-06-27 00:41:40 -04001014 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 if (!acpi_device_dir(device)) {
1017 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001018 vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001020 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 acpi_device_dir(device)->owner = THIS_MODULE;
1022 }
1023
1024 /* 'info' [R] */
1025 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1026 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001027 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 else {
1029 entry->proc_fops = &acpi_video_device_info_fops;
1030 entry->data = acpi_driver_data(device);
1031 entry->owner = THIS_MODULE;
1032 }
1033
1034 /* 'state' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001035 entry =
1036 create_proc_entry("state", S_IFREG | S_IRUGO | S_IWUSR,
1037 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001039 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001041 acpi_video_device_state_fops.write = acpi_video_device_write_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 entry->proc_fops = &acpi_video_device_state_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 entry->data = acpi_driver_data(device);
1044 entry->owner = THIS_MODULE;
1045 }
1046
1047 /* 'brightness' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001048 entry =
1049 create_proc_entry("brightness", S_IFREG | S_IRUGO | S_IWUSR,
1050 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001052 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001054 acpi_video_device_brightness_fops.write = acpi_video_device_write_brightness;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 entry->proc_fops = &acpi_video_device_brightness_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 entry->data = acpi_driver_data(device);
1057 entry->owner = THIS_MODULE;
1058 }
1059
1060 /* 'EDID' [R] */
1061 entry = create_proc_entry("EDID", S_IRUGO, acpi_device_dir(device));
1062 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001063 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 else {
1065 entry->proc_fops = &acpi_video_device_EDID_fops;
1066 entry->data = acpi_driver_data(device);
1067 entry->owner = THIS_MODULE;
1068 }
1069
Patrick Mocheld550d982006-06-27 00:41:40 -04001070 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071}
1072
Len Brown4be44fc2005-08-05 00:44:28 -04001073static int acpi_video_device_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 struct acpi_video_device *vid_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001077 vid_dev = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04001079 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 if (acpi_device_dir(device)) {
1082 remove_proc_entry("info", acpi_device_dir(device));
1083 remove_proc_entry("state", acpi_device_dir(device));
1084 remove_proc_entry("brightness", acpi_device_dir(device));
1085 remove_proc_entry("EDID", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001086 remove_proc_entry(acpi_device_bid(device), vid_dev->video->dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 acpi_device_dir(device) = NULL;
1088 }
1089
Patrick Mocheld550d982006-06-27 00:41:40 -04001090 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093/* video bus */
Len Brown4be44fc2005-08-05 00:44:28 -04001094static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001096 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 if (!video)
1100 goto end;
1101
1102 seq_printf(seq, "Switching heads: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001103 video->flags.multihead ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 seq_printf(seq, "Video ROM: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001105 video->flags.rom ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 seq_printf(seq, "Device to be POSTed on boot: %s\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001107 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Len Brown4be44fc2005-08-05 00:44:28 -04001109 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001110 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
Len Brown4be44fc2005-08-05 00:44:28 -04001113static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
Len Brown4be44fc2005-08-05 00:44:28 -04001115 return single_open(file, acpi_video_bus_info_seq_show,
1116 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
Len Brown4be44fc2005-08-05 00:44:28 -04001119static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001121 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 if (!video)
1125 goto end;
1126
1127 printk(KERN_INFO PREFIX "Please implement %s\n", __FUNCTION__);
1128 seq_printf(seq, "<TODO>\n");
1129
Len Brown4be44fc2005-08-05 00:44:28 -04001130 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001131 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Len Brown4be44fc2005-08-05 00:44:28 -04001134static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
1136 return single_open(file, acpi_video_bus_ROM_seq_show, PDE(inode)->data);
1137}
1138
Len Brown4be44fc2005-08-05 00:44:28 -04001139static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001141 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001142 unsigned long options;
1143 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 if (!video)
1147 goto end;
1148
1149 status = acpi_video_bus_POST_options(video, &options);
1150 if (ACPI_SUCCESS(status)) {
1151 if (!(options & 1)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001152 printk(KERN_WARNING PREFIX
1153 "The motherboard VGA device is not listed as a possible POST device.\n");
1154 printk(KERN_WARNING PREFIX
Julius Volz98fb8fe2007-02-20 16:38:40 +01001155 "This indicates a BIOS bug. Please contact the manufacturer.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
1157 printk("%lx\n", options);
Julius Volz98fb8fe2007-02-20 16:38:40 +01001158 seq_printf(seq, "can POST: <integrated video>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 if (options & 2)
1160 seq_printf(seq, " <PCI video>");
1161 if (options & 4)
1162 seq_printf(seq, " <AGP video>");
1163 seq_putc(seq, '\n');
1164 } else
1165 seq_printf(seq, "<not supported>\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001166 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001167 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
1170static int
Len Brown4be44fc2005-08-05 00:44:28 -04001171acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Len Brown4be44fc2005-08-05 00:44:28 -04001173 return single_open(file, acpi_video_bus_POST_info_seq_show,
1174 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
Len Brown4be44fc2005-08-05 00:44:28 -04001177static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001179 struct acpi_video_bus *video = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001180 int status;
1181 unsigned long id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 if (!video)
1185 goto end;
1186
Len Brown4be44fc2005-08-05 00:44:28 -04001187 status = acpi_video_bus_get_POST(video, &id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 if (!ACPI_SUCCESS(status)) {
1189 seq_printf(seq, "<not supported>\n");
1190 goto end;
1191 }
Julius Volz98fb8fe2007-02-20 16:38:40 +01001192 seq_printf(seq, "device POSTed is <%s>\n", device_decode[id & 3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Len Brown4be44fc2005-08-05 00:44:28 -04001194 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001195 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
Len Brown4be44fc2005-08-05 00:44:28 -04001198static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001200 struct acpi_video_bus *video = seq->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Len Brown4be44fc2005-08-05 00:44:28 -04001203 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Patrick Mocheld550d982006-06-27 00:41:40 -04001205 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
1207
Len Brown4be44fc2005-08-05 00:44:28 -04001208static int acpi_video_bus_POST_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Len Brown4be44fc2005-08-05 00:44:28 -04001210 return single_open(file, acpi_video_bus_POST_seq_show,
1211 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Len Brown4be44fc2005-08-05 00:44:28 -04001214static int acpi_video_bus_DOS_open_fs(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215{
1216 return single_open(file, acpi_video_bus_DOS_seq_show, PDE(inode)->data);
1217}
1218
1219static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001220acpi_video_bus_write_POST(struct file *file,
1221 const char __user * buffer,
1222 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
Len Brown4be44fc2005-08-05 00:44:28 -04001224 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001225 struct seq_file *m = file->private_data;
1226 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001227 char str[12] = { 0 };
1228 unsigned long opt, options;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001232 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
1234 status = acpi_video_bus_POST_options(video, &options);
1235 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001236 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001239 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 str[count] = 0;
1242 opt = strtoul(str, NULL, 0);
1243 if (opt > 3)
Patrick Mocheld550d982006-06-27 00:41:40 -04001244 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Julius Volz98fb8fe2007-02-20 16:38:40 +01001246 /* just in case an OEM 'forgot' the motherboard... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 options |= 1;
1248
1249 if (options & (1ul << opt)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001250 status = acpi_video_bus_set_POST(video, opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001252 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254 }
1255
Patrick Mocheld550d982006-06-27 00:41:40 -04001256 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257}
1258
1259static ssize_t
Len Brown4be44fc2005-08-05 00:44:28 -04001260acpi_video_bus_write_DOS(struct file *file,
1261 const char __user * buffer,
1262 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263{
Len Brown4be44fc2005-08-05 00:44:28 -04001264 int status;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001265 struct seq_file *m = file->private_data;
1266 struct acpi_video_bus *video = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001267 char str[12] = { 0 };
1268 unsigned long opt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 if (!video || count + 1 > sizeof str)
Patrick Mocheld550d982006-06-27 00:41:40 -04001272 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
1274 if (copy_from_user(str, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001275 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 str[count] = 0;
1278 opt = strtoul(str, NULL, 0);
1279 if (opt > 7)
Patrick Mocheld550d982006-06-27 00:41:40 -04001280 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Len Brown4be44fc2005-08-05 00:44:28 -04001282 status = acpi_video_bus_DOS(video, opt & 0x3, (opt & 0x4) >> 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 if (!ACPI_SUCCESS(status))
Patrick Mocheld550d982006-06-27 00:41:40 -04001285 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
Patrick Mocheld550d982006-06-27 00:41:40 -04001287 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288}
1289
Len Brown4be44fc2005-08-05 00:44:28 -04001290static int acpi_video_bus_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291{
Len Brown4be44fc2005-08-05 00:44:28 -04001292 struct proc_dir_entry *entry = NULL;
1293 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001296 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298 if (!acpi_device_dir(device)) {
1299 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
Len Brown4be44fc2005-08-05 00:44:28 -04001300 acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 if (!acpi_device_dir(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001302 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 video->dir = acpi_device_dir(device);
1304 acpi_device_dir(device)->owner = THIS_MODULE;
1305 }
1306
1307 /* 'info' [R] */
1308 entry = create_proc_entry("info", S_IRUGO, acpi_device_dir(device));
1309 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001310 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 else {
1312 entry->proc_fops = &acpi_video_bus_info_fops;
1313 entry->data = acpi_driver_data(device);
1314 entry->owner = THIS_MODULE;
1315 }
1316
1317 /* 'ROM' [R] */
1318 entry = create_proc_entry("ROM", S_IRUGO, acpi_device_dir(device));
1319 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001320 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 else {
1322 entry->proc_fops = &acpi_video_bus_ROM_fops;
1323 entry->data = acpi_driver_data(device);
1324 entry->owner = THIS_MODULE;
1325 }
1326
1327 /* 'POST_info' [R] */
Len Brown4be44fc2005-08-05 00:44:28 -04001328 entry =
1329 create_proc_entry("POST_info", S_IRUGO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001331 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 else {
1333 entry->proc_fops = &acpi_video_bus_POST_info_fops;
1334 entry->data = acpi_driver_data(device);
1335 entry->owner = THIS_MODULE;
1336 }
1337
1338 /* 'POST' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001339 entry =
1340 create_proc_entry("POST", S_IFREG | S_IRUGO | S_IRUSR,
1341 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001343 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001345 acpi_video_bus_POST_fops.write = acpi_video_bus_write_POST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 entry->proc_fops = &acpi_video_bus_POST_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 entry->data = acpi_driver_data(device);
1348 entry->owner = THIS_MODULE;
1349 }
1350
1351 /* 'DOS' [R/W] */
Len Brown4be44fc2005-08-05 00:44:28 -04001352 entry =
1353 create_proc_entry("DOS", S_IFREG | S_IRUGO | S_IRUSR,
1354 acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 if (!entry)
Patrick Mocheld550d982006-06-27 00:41:40 -04001356 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 else {
Arjan van de Vend479e902006-01-06 16:47:00 -05001358 acpi_video_bus_DOS_fops.write = acpi_video_bus_write_DOS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 entry->proc_fops = &acpi_video_bus_DOS_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 entry->data = acpi_driver_data(device);
1361 entry->owner = THIS_MODULE;
1362 }
1363
Patrick Mocheld550d982006-06-27 00:41:40 -04001364 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365}
1366
Len Brown4be44fc2005-08-05 00:44:28 -04001367static int acpi_video_bus_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368{
Len Brown4be44fc2005-08-05 00:44:28 -04001369 struct acpi_video_bus *video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001372 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373
1374 if (acpi_device_dir(device)) {
1375 remove_proc_entry("info", acpi_device_dir(device));
1376 remove_proc_entry("ROM", acpi_device_dir(device));
1377 remove_proc_entry("POST_info", acpi_device_dir(device));
1378 remove_proc_entry("POST", acpi_device_dir(device));
1379 remove_proc_entry("DOS", acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001380 remove_proc_entry(acpi_device_bid(device), acpi_video_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 acpi_device_dir(device) = NULL;
1382 }
1383
Patrick Mocheld550d982006-06-27 00:41:40 -04001384 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385}
1386
1387/* --------------------------------------------------------------------------
1388 Driver Interface
1389 -------------------------------------------------------------------------- */
1390
1391/* device interface */
Rui Zhang82cae992007-01-03 23:40:53 -05001392static struct acpi_video_device_attrib*
1393acpi_video_get_device_attr(struct acpi_video_bus *video, unsigned long device_id)
1394{
1395 int count;
1396
1397 for(count = 0; count < video->attached_count; count++)
1398 if((video->attached_array[count].value.int_val & 0xffff) == device_id)
1399 return &(video->attached_array[count].value.attrib);
1400 return NULL;
1401}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
1403static int
Len Brown4be44fc2005-08-05 00:44:28 -04001404acpi_video_bus_get_one_device(struct acpi_device *device,
1405 struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406{
Len Brown4be44fc2005-08-05 00:44:28 -04001407 unsigned long device_id;
Yu, Luming973bf492006-04-27 05:25:00 -04001408 int status;
Len Brown4be44fc2005-08-05 00:44:28 -04001409 struct acpi_video_device *data;
Rui Zhang82cae992007-01-03 23:40:53 -05001410 struct acpi_video_device_attrib* attribute;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 if (!device || !video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001413 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
Len Brown4be44fc2005-08-05 00:44:28 -04001415 status =
1416 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 if (ACPI_SUCCESS(status)) {
1418
Burman Yan36bcbec2006-12-19 12:56:11 -08001419 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 if (!data)
Patrick Mocheld550d982006-06-27 00:41:40 -04001421 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1424 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1425 acpi_driver_data(device) = data;
1426
1427 data->device_id = device_id;
1428 data->video = video;
1429 data->dev = device;
1430
Rui Zhang82cae992007-01-03 23:40:53 -05001431 attribute = acpi_video_get_device_attr(video, device_id);
1432
1433 if((attribute != NULL) && attribute->device_id_scheme) {
1434 switch (attribute->display_type) {
1435 case ACPI_VIDEO_DISPLAY_CRT:
1436 data->flags.crt = 1;
1437 break;
1438 case ACPI_VIDEO_DISPLAY_TV:
1439 data->flags.tvout = 1;
1440 break;
1441 case ACPI_VIDEO_DISPLAY_DVI:
1442 data->flags.dvi = 1;
1443 break;
1444 case ACPI_VIDEO_DISPLAY_LCD:
1445 data->flags.lcd = 1;
1446 break;
1447 default:
1448 data->flags.unknown = 1;
1449 break;
1450 }
1451 if(attribute->bios_can_detect)
1452 data->flags.bios = 1;
1453 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 data->flags.unknown = 1;
Len Brown4be44fc2005-08-05 00:44:28 -04001455
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 acpi_video_device_bind(video, data);
1457 acpi_video_device_find_cap(data);
1458
Patrick Mochel90130262006-05-19 16:54:48 -04001459 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001460 ACPI_DEVICE_NOTIFY,
1461 acpi_video_device_notify,
1462 data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 if (ACPI_FAILURE(status)) {
1464 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001465 "Error installing notify handler\n"));
Yu, Luming973bf492006-04-27 05:25:00 -04001466 if(data->brightness)
1467 kfree(data->brightness->levels);
1468 kfree(data->brightness);
1469 kfree(data);
1470 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 }
1472
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001473 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 list_add_tail(&data->entry, &video->video_device_list);
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001475 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 acpi_video_device_add_fs(device);
1478
Patrick Mocheld550d982006-06-27 00:41:40 -04001479 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
1481
Patrick Mocheld550d982006-06-27 00:41:40 -04001482 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
1485/*
1486 * Arg:
1487 * video : video bus device
1488 *
1489 * Return:
1490 * none
1491 *
1492 * Enumerate the video device list of the video bus,
1493 * bind the ids with the corresponding video devices
1494 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001495 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Len Brown4be44fc2005-08-05 00:44:28 -04001497static void acpi_video_device_rebind(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498{
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001499 struct acpi_video_device *dev;
1500
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001501 mutex_lock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001502
1503 list_for_each_entry(dev, &video->video_device_list, entry)
Len Brown4be44fc2005-08-05 00:44:28 -04001504 acpi_video_device_bind(video, dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001505
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001506 mutex_unlock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
1509/*
1510 * Arg:
1511 * video : video bus device
1512 * device : video output device under the video
1513 * bus
1514 *
1515 * Return:
1516 * none
1517 *
1518 * Bind the ids with the corresponding video devices
1519 * under the video bus.
Len Brown4be44fc2005-08-05 00:44:28 -04001520 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522static void
Len Brown4be44fc2005-08-05 00:44:28 -04001523acpi_video_device_bind(struct acpi_video_bus *video,
1524 struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525{
Len Brown4be44fc2005-08-05 00:44:28 -04001526 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528#define IDS_VAL(i) video->attached_array[i].value.int_val
1529#define IDS_BIND(i) video->attached_array[i].bind_info
Len Brown4be44fc2005-08-05 00:44:28 -04001530
1531 for (i = 0; IDS_VAL(i) != ACPI_VIDEO_HEAD_INVALID &&
1532 i < video->attached_count; i++) {
1533 if (device->device_id == (IDS_VAL(i) & 0xffff)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 IDS_BIND(i) = device;
1535 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "device_bind %d\n", i));
1536 }
1537 }
1538#undef IDS_VAL
1539#undef IDS_BIND
1540}
1541
1542/*
1543 * Arg:
1544 * video : video bus device
1545 *
1546 * Return:
1547 * < 0 : error
1548 *
1549 * Call _DOD to enumerate all devices attached to display adapter
1550 *
Len Brown4be44fc2005-08-05 00:44:28 -04001551 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1554{
Len Brown4be44fc2005-08-05 00:44:28 -04001555 int status;
1556 int count;
1557 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 struct acpi_video_enumerated_device *active_device_list;
Len Brown4be44fc2005-08-05 00:44:28 -04001559 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1560 union acpi_object *dod = NULL;
1561 union acpi_object *obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
Patrick Mochel90130262006-05-19 16:54:48 -04001563 status = acpi_evaluate_object(video->device->handle, "_DOD", NULL, &buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 if (!ACPI_SUCCESS(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001565 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _DOD"));
Patrick Mocheld550d982006-06-27 00:41:40 -04001566 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 }
1568
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001569 dod = buffer.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001571 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 status = -EFAULT;
1573 goto out;
1574 }
1575
1576 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001577 dod->package.count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Len Brown4be44fc2005-08-05 00:44:28 -04001579 active_device_list = kmalloc((1 +
1580 dod->package.count) *
1581 sizeof(struct
1582 acpi_video_enumerated_device),
1583 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 if (!active_device_list) {
1586 status = -ENOMEM;
1587 goto out;
1588 }
1589
1590 count = 0;
1591 for (i = 0; i < dod->package.count; i++) {
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001592 obj = &dod->package.elements[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 if (obj->type != ACPI_TYPE_INTEGER) {
Len Brown64684632006-06-26 23:41:38 -04001595 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001596 active_device_list[i].value.int_val =
1597 ACPI_VIDEO_HEAD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 }
1599 active_device_list[i].value.int_val = obj->integer.value;
1600 active_device_list[i].bind_info = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001601 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "dod element[%d] = %d\n", i,
1602 (int)obj->integer.value));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 count++;
1604 }
1605 active_device_list[count].value.int_val = ACPI_VIDEO_HEAD_END;
1606
Jesper Juhl6044ec82005-11-07 01:01:32 -08001607 kfree(video->attached_array);
Len Brown4be44fc2005-08-05 00:44:28 -04001608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 video->attached_array = active_device_list;
1610 video->attached_count = count;
Len Brown4be44fc2005-08-05 00:44:28 -04001611 out:
Len Brown02438d82006-06-30 03:19:10 -04001612 kfree(buffer.pointer);
Patrick Mocheld550d982006-06-27 00:41:40 -04001613 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
Len Brown4be44fc2005-08-05 00:44:28 -04001616static int
1617acpi_video_get_next_level(struct acpi_video_device *device,
1618 u32 level_current, u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001620 int min, max, min_above, max_below, i, l, delta = 255;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001621 max = max_below = 0;
1622 min = min_above = 255;
Alexey Starikovskiy63f0edf2007-09-03 16:30:08 +04001623 /* Find closest level to level_current */
1624 for (i = 0; i < device->brightness->count; i++) {
1625 l = device->brightness->levels[i];
1626 if (abs(l - level_current) < abs(delta)) {
1627 delta = l - level_current;
1628 if (!delta)
1629 break;
1630 }
1631 }
1632 /* Ajust level_current to closest available level */
1633 level_current += delta;
Thomas Tuttlef4715182006-12-19 12:56:14 -08001634 for (i = 0; i < device->brightness->count; i++) {
1635 l = device->brightness->levels[i];
1636 if (l < min)
1637 min = l;
1638 if (l > max)
1639 max = l;
1640 if (l < min_above && l > level_current)
1641 min_above = l;
1642 if (l > max_below && l < level_current)
1643 max_below = l;
1644 }
1645
1646 switch (event) {
1647 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1648 return (level_current < max) ? min_above : min;
1649 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1650 return (level_current < max) ? min_above : max;
1651 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1652 return (level_current > min) ? max_below : min;
1653 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1654 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1655 return 0;
1656 default:
1657 return level_current;
1658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659}
1660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661static void
Len Brown4be44fc2005-08-05 00:44:28 -04001662acpi_video_switch_brightness(struct acpi_video_device *device, int event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
1664 unsigned long level_current, level_next;
1665 acpi_video_device_lcd_get_level_current(device, &level_current);
1666 level_next = acpi_video_get_next_level(device, level_current, event);
1667 acpi_video_device_lcd_set_level(device, level_next);
1668}
1669
1670static int
Len Brown4be44fc2005-08-05 00:44:28 -04001671acpi_video_bus_get_devices(struct acpi_video_bus *video,
1672 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673{
Len Brown4be44fc2005-08-05 00:44:28 -04001674 int status = 0;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001675 struct acpi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676
1677 acpi_video_device_enumerate(video);
1678
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001679 list_for_each_entry(dev, &device->children, node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
1681 status = acpi_video_bus_get_one_device(dev, video);
1682 if (ACPI_FAILURE(status)) {
Thomas Renningera6fc6722006-06-26 23:58:43 -04001683 ACPI_EXCEPTION((AE_INFO, status, "Cant attach device"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 continue;
1685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 }
Patrick Mocheld550d982006-06-27 00:41:40 -04001687 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Len Brown4be44fc2005-08-05 00:44:28 -04001690static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Karol Kozimor031ec772005-07-30 04:18:00 -04001692 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 struct acpi_video_bus *video;
1694
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
1696 if (!device || !device->video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001697 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
1699 video = device->video;
1700
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 acpi_video_device_remove_fs(device->dev);
1702
Patrick Mochel90130262006-05-19 16:54:48 -04001703 status = acpi_remove_notify_handler(device->dev->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001704 ACPI_DEVICE_NOTIFY,
1705 acpi_video_device_notify);
Richard Purdie599a52d2007-02-10 23:07:48 +00001706 backlight_device_unregister(device->backlight);
Luming Yu23b0f012007-05-09 21:07:05 +08001707 video_output_unregister(device->output_dev);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001708
Patrick Mocheld550d982006-06-27 00:41:40 -04001709 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
Len Brown4be44fc2005-08-05 00:44:28 -04001712static int acpi_video_bus_put_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713{
Len Brown4be44fc2005-08-05 00:44:28 -04001714 int status;
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001715 struct acpi_video_device *dev, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001717 mutex_lock(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001719 list_for_each_entry_safe(dev, next, &video->video_device_list, entry) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001721 status = acpi_video_bus_put_one_device(dev);
Len Brown4be44fc2005-08-05 00:44:28 -04001722 if (ACPI_FAILURE(status))
1723 printk(KERN_WARNING PREFIX
1724 "hhuuhhuu bug in acpi video driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001726 if (dev->brightness) {
1727 kfree(dev->brightness->levels);
1728 kfree(dev->brightness);
1729 }
1730 list_del(&dev->entry);
1731 kfree(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 }
1733
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001734 mutex_unlock(&video->device_list_lock);
Dmitry Torokhovff102ea2007-11-05 11:43:31 -05001735
Patrick Mocheld550d982006-06-27 00:41:40 -04001736 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737}
1738
1739/* acpi_video interface */
1740
Len Brown4be44fc2005-08-05 00:44:28 -04001741static int acpi_video_bus_start_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742{
Zhang Ruia21101c2007-09-14 11:46:22 +08001743 return acpi_video_bus_DOS(video, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744}
1745
Len Brown4be44fc2005-08-05 00:44:28 -04001746static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
1748 return acpi_video_bus_DOS(video, 0, 1);
1749}
1750
Len Brown4be44fc2005-08-05 00:44:28 -04001751static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001753 struct acpi_video_bus *video = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001754 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001755 struct input_dev *input;
1756 int keycode;
1757
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001759 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001761 device = video->device;
Luming Yue9dab192007-08-20 18:23:53 +08001762 input = video->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
1764 switch (event) {
Julius Volz98fb8fe2007-02-20 16:38:40 +01001765 case ACPI_VIDEO_NOTIFY_SWITCH: /* User requested a switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 * most likely via hotkey. */
Len Brown14e04fb2007-08-23 15:20:26 -04001767 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001768 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 break;
1770
Julius Volz98fb8fe2007-02-20 16:38:40 +01001771 case ACPI_VIDEO_NOTIFY_PROBE: /* User plugged in or removed a video
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 * connector. */
1773 acpi_video_device_enumerate(video);
1774 acpi_video_device_rebind(video);
Len Brown14e04fb2007-08-23 15:20:26 -04001775 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001776 keycode = KEY_SWITCHVIDEOMODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 break;
1778
Len Brown4be44fc2005-08-05 00:44:28 -04001779 case ACPI_VIDEO_NOTIFY_CYCLE: /* Cycle Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001780 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001781 keycode = KEY_SWITCHVIDEOMODE;
1782 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001783 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: /* Next Display output hotkey pressed. */
Len Brown25c87f72007-08-25 01:44:01 -04001784 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001785 keycode = KEY_VIDEO_NEXT;
1786 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001787 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: /* previous Display output hotkey pressed. */
Len Brown14e04fb2007-08-23 15:20:26 -04001788 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001789 keycode = KEY_VIDEO_PREV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 break;
1791
1792 default:
Luming Yue9dab192007-08-20 18:23:53 +08001793 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001795 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 break;
1797 }
1798
Zhang Rui7761f632008-01-25 14:48:12 +08001799 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001800 input_report_key(input, keycode, 1);
1801 input_sync(input);
1802 input_report_key(input, keycode, 0);
1803 input_sync(input);
1804
Patrick Mocheld550d982006-06-27 00:41:40 -04001805 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806}
1807
Len Brown4be44fc2005-08-05 00:44:28 -04001808static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001810 struct acpi_video_device *video_device = data;
Len Brown4be44fc2005-08-05 00:44:28 -04001811 struct acpi_device *device = NULL;
Luming Yue9dab192007-08-20 18:23:53 +08001812 struct acpi_video_bus *bus;
1813 struct input_dev *input;
1814 int keycode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 if (!video_device)
Patrick Mocheld550d982006-06-27 00:41:40 -04001817 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001819 device = video_device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001820 bus = video_device->video;
1821 input = bus->input;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 switch (event) {
Len Brown4be44fc2005-08-05 00:44:28 -04001824 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS: /* Cycle brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001825 if (brightness_switch_enabled)
1826 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001827 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001828 keycode = KEY_BRIGHTNESS_CYCLE;
1829 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001830 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS: /* Increase brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001831 if (brightness_switch_enabled)
1832 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001833 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001834 keycode = KEY_BRIGHTNESSUP;
1835 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001836 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS: /* Decrease brightness */
Zhang Rui8a681a42008-01-25 14:47:49 +08001837 if (brightness_switch_enabled)
1838 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001839 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001840 keycode = KEY_BRIGHTNESSDOWN;
1841 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001842 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS: /* zero brightnesss */
Zhang Rui8a681a42008-01-25 14:47:49 +08001843 if (brightness_switch_enabled)
1844 acpi_video_switch_brightness(video_device, event);
Len Brown25c87f72007-08-25 01:44:01 -04001845 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001846 keycode = KEY_BRIGHTNESS_ZERO;
1847 break;
Len Brown4be44fc2005-08-05 00:44:28 -04001848 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF: /* display device off */
Zhang Rui8a681a42008-01-25 14:47:49 +08001849 if (brightness_switch_enabled)
1850 acpi_video_switch_brightness(video_device, event);
Len Brown14e04fb2007-08-23 15:20:26 -04001851 acpi_bus_generate_proc_event(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001852 keycode = KEY_DISPLAY_OFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 break;
1854 default:
Luming Yue9dab192007-08-20 18:23:53 +08001855 keycode = KEY_UNKNOWN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -04001857 "Unsupported event [0x%x]\n", event));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 break;
1859 }
Luming Yue9dab192007-08-20 18:23:53 +08001860
Zhang Rui7761f632008-01-25 14:48:12 +08001861 acpi_notifier_call_chain(device, event, 0);
Luming Yue9dab192007-08-20 18:23:53 +08001862 input_report_key(input, keycode, 1);
1863 input_sync(input);
1864 input_report_key(input, keycode, 0);
1865 input_sync(input);
1866
Patrick Mocheld550d982006-06-27 00:41:40 -04001867 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868}
1869
Zhang Ruie6d9da12007-08-25 02:23:31 -04001870static int instance;
Matthew Garrett863c1492008-02-04 23:31:24 -08001871static int acpi_video_resume(struct acpi_device *device)
1872{
1873 struct acpi_video_bus *video;
1874 struct acpi_video_device *video_device;
1875 int i;
1876
1877 if (!device || !acpi_driver_data(device))
1878 return -EINVAL;
1879
1880 video = acpi_driver_data(device);
1881
1882 for (i = 0; i < video->attached_count; i++) {
1883 video_device = video->attached_array[i].bind_info;
1884 if (video_device && video_device->backlight)
1885 acpi_video_set_brightness(video_device->backlight);
1886 }
1887 return AE_OK;
1888}
1889
Len Brown4be44fc2005-08-05 00:44:28 -04001890static int acpi_video_bus_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001892 acpi_status status;
1893 struct acpi_video_bus *video;
Luming Yue9dab192007-08-20 18:23:53 +08001894 struct input_dev *input;
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001895 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Burman Yan36bcbec2006-12-19 12:56:11 -08001897 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 if (!video)
Patrick Mocheld550d982006-06-27 00:41:40 -04001899 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Zhang Ruie6d9da12007-08-25 02:23:31 -04001901 /* a hack to fix the duplicate name "VID" problem on T61 */
1902 if (!strcmp(device->pnp.bus_id, "VID")) {
1903 if (instance)
1904 device->pnp.bus_id[3] = '0' + instance;
1905 instance ++;
1906 }
1907
Patrick Mochele6afa0d2006-05-19 16:54:40 -04001908 video->device = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
1910 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1911 acpi_driver_data(device) = video;
1912
1913 acpi_video_bus_find_cap(video);
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001914 error = acpi_video_bus_check(video);
1915 if (error)
1916 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001918 error = acpi_video_bus_add_fs(device);
1919 if (error)
1920 goto err_free_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
Dmitry Torokhovbbac81f2007-11-05 11:43:32 -05001922 mutex_init(&video->device_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 INIT_LIST_HEAD(&video->video_device_list);
1924
1925 acpi_video_bus_get_devices(video, device);
1926 acpi_video_bus_start_devices(video);
1927
Patrick Mochel90130262006-05-19 16:54:48 -04001928 status = acpi_install_notify_handler(device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04001929 ACPI_DEVICE_NOTIFY,
1930 acpi_video_bus_notify, video);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 if (ACPI_FAILURE(status)) {
1932 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
Len Brown4be44fc2005-08-05 00:44:28 -04001933 "Error installing notify handler\n"));
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001934 error = -ENODEV;
1935 goto err_stop_video;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 }
1937
Luming Yue9dab192007-08-20 18:23:53 +08001938 video->input = input = input_allocate_device();
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001939 if (!input) {
1940 error = -ENOMEM;
1941 goto err_uninstall_notify;
1942 }
Luming Yue9dab192007-08-20 18:23:53 +08001943
1944 snprintf(video->phys, sizeof(video->phys),
1945 "%s/video/input0", acpi_device_hid(video->device));
1946
1947 input->name = acpi_device_name(video->device);
1948 input->phys = video->phys;
1949 input->id.bustype = BUS_HOST;
1950 input->id.product = 0x06;
Dmitry Torokhov91c05c62007-11-05 11:43:29 -05001951 input->dev.parent = &device->dev;
Luming Yue9dab192007-08-20 18:23:53 +08001952 input->evbit[0] = BIT(EV_KEY);
1953 set_bit(KEY_SWITCHVIDEOMODE, input->keybit);
1954 set_bit(KEY_VIDEO_NEXT, input->keybit);
1955 set_bit(KEY_VIDEO_PREV, input->keybit);
1956 set_bit(KEY_BRIGHTNESS_CYCLE, input->keybit);
1957 set_bit(KEY_BRIGHTNESSUP, input->keybit);
1958 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
1959 set_bit(KEY_BRIGHTNESS_ZERO, input->keybit);
1960 set_bit(KEY_DISPLAY_OFF, input->keybit);
1961 set_bit(KEY_UNKNOWN, input->keybit);
Luming Yue9dab192007-08-20 18:23:53 +08001962
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001963 error = input_register_device(input);
1964 if (error)
1965 goto err_free_input_dev;
Luming Yue9dab192007-08-20 18:23:53 +08001966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 printk(KERN_INFO PREFIX "%s [%s] (multi-head: %s rom: %s post: %s)\n",
Len Brown4be44fc2005-08-05 00:44:28 -04001968 ACPI_VIDEO_DEVICE_NAME, acpi_device_bid(device),
1969 video->flags.multihead ? "yes" : "no",
1970 video->flags.rom ? "yes" : "no",
1971 video->flags.post ? "yes" : "no");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001973 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
Dmitry Torokhovf51e8392007-11-05 11:43:30 -05001975 err_free_input_dev:
1976 input_free_device(input);
1977 err_uninstall_notify:
1978 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1979 acpi_video_bus_notify);
1980 err_stop_video:
1981 acpi_video_bus_stop_devices(video);
1982 acpi_video_bus_put_devices(video);
1983 kfree(video->attached_array);
1984 acpi_video_bus_remove_fs(device);
1985 err_free_video:
1986 kfree(video);
1987 acpi_driver_data(device) = NULL;
1988
1989 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990}
1991
Len Brown4be44fc2005-08-05 00:44:28 -04001992static int acpi_video_bus_remove(struct acpi_device *device, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993{
Len Brown4be44fc2005-08-05 00:44:28 -04001994 acpi_status status = 0;
1995 struct acpi_video_bus *video = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
1998 if (!device || !acpi_driver_data(device))
Patrick Mocheld550d982006-06-27 00:41:40 -04001999 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
Jan Engelhardt50dd0962006-10-01 00:28:50 +02002001 video = acpi_driver_data(device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
2003 acpi_video_bus_stop_devices(video);
2004
Patrick Mochel90130262006-05-19 16:54:48 -04002005 status = acpi_remove_notify_handler(video->device->handle,
Len Brown4be44fc2005-08-05 00:44:28 -04002006 ACPI_DEVICE_NOTIFY,
2007 acpi_video_bus_notify);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
2009 acpi_video_bus_put_devices(video);
2010 acpi_video_bus_remove_fs(device);
2011
Luming Yue9dab192007-08-20 18:23:53 +08002012 input_unregister_device(video->input);
Jesper Juhl6044ec82005-11-07 01:01:32 -08002013 kfree(video->attached_array);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 kfree(video);
2015
Patrick Mocheld550d982006-06-27 00:41:40 -04002016 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017}
2018
Len Brown4be44fc2005-08-05 00:44:28 -04002019static int __init acpi_video_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
Len Brown4be44fc2005-08-05 00:44:28 -04002021 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
2024 /*
Len Brown4be44fc2005-08-05 00:44:28 -04002025 acpi_dbg_level = 0xFFFFFFFF;
2026 acpi_dbg_layer = 0x08000000;
2027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029 acpi_video_dir = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir);
2030 if (!acpi_video_dir)
Patrick Mocheld550d982006-06-27 00:41:40 -04002031 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 acpi_video_dir->owner = THIS_MODULE;
2033
2034 result = acpi_bus_register_driver(&acpi_video_bus);
2035 if (result < 0) {
2036 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
Patrick Mocheld550d982006-06-27 00:41:40 -04002037 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
2039
Patrick Mocheld550d982006-06-27 00:41:40 -04002040 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041}
2042
Len Brown4be44fc2005-08-05 00:44:28 -04002043static void __exit acpi_video_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 acpi_bus_unregister_driver(&acpi_video_bus);
2047
2048 remove_proc_entry(ACPI_VIDEO_CLASS, acpi_root_dir);
2049
Patrick Mocheld550d982006-06-27 00:41:40 -04002050 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051}
2052
2053module_init(acpi_video_init);
2054module_exit(acpi_video_exit);