2 * video.c - ACPI Video Driver ($Revision:$)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
24 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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>
32 #include <linux/mutex.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/input.h>
36 #include <linux/backlight.h>
37 #include <linux/thermal.h>
38 #include <linux/video_output.h>
39 #include <asm/uaccess.h>
41 #include <acpi/acpi_bus.h>
42 #include <acpi/acpi_drivers.h>
44 #define ACPI_VIDEO_COMPONENT 0x08000000
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
61 #define ACPI_VIDEO_HEAD_END (~0u)
62 #define MAX_NAME_LEN 20
64 #define ACPI_VIDEO_DISPLAY_CRT 1
65 #define ACPI_VIDEO_DISPLAY_TV 2
66 #define ACPI_VIDEO_DISPLAY_DVI 3
67 #define ACPI_VIDEO_DISPLAY_LCD 4
69 #define _COMPONENT ACPI_VIDEO_COMPONENT
70 ACPI_MODULE_NAME("video");
72 MODULE_AUTHOR("Bruno Ducrot");
73 MODULE_DESCRIPTION("ACPI Video Driver");
74 MODULE_LICENSE("GPL");
76 static int brightness_switch_enabled
= 1;
77 module_param(brightness_switch_enabled
, bool, 0644);
79 static int acpi_video_bus_add(struct acpi_device
*device
);
80 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
81 static int acpi_video_resume(struct acpi_device
*device
);
83 static const struct acpi_device_id video_device_ids
[] = {
87 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
89 static struct acpi_driver acpi_video_bus
= {
91 .class = ACPI_VIDEO_CLASS
,
92 .ids
= video_device_ids
,
94 .add
= acpi_video_bus_add
,
95 .remove
= acpi_video_bus_remove
,
96 .resume
= acpi_video_resume
,
100 struct acpi_video_bus_flags
{
101 u8 multihead
:1; /* can switch video heads */
102 u8 rom
:1; /* can retrieve a video rom */
103 u8 post
:1; /* can configure the head to */
107 struct acpi_video_bus_cap
{
108 u8 _DOS
:1; /*Enable/Disable output switching */
109 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
110 u8 _ROM
:1; /*Get ROM Data */
111 u8 _GPD
:1; /*Get POST Device */
112 u8 _SPD
:1; /*Set POST Device */
113 u8 _VPO
:1; /*Video POST Options */
117 struct acpi_video_device_attrib
{
118 u32 display_index
:4; /* A zero-based instance of the Display */
119 u32 display_port_attachment
:4; /*This field differentiates the display type */
120 u32 display_type
:4; /*Describe the specific type in use */
121 u32 vendor_specific
:4; /*Chipset Vendor Specific */
122 u32 bios_can_detect
:1; /*BIOS can detect the device */
123 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
125 u32 pipe_id
:3; /*For VGA multiple-head devices. */
126 u32 reserved
:10; /*Must be 0 */
127 u32 device_id_scheme
:1; /*Device ID Scheme */
130 struct acpi_video_enumerated_device
{
133 struct acpi_video_device_attrib attrib
;
135 struct acpi_video_device
*bind_info
;
138 struct acpi_video_bus
{
139 struct acpi_device
*device
;
141 struct acpi_video_enumerated_device
*attached_array
;
143 struct acpi_video_bus_cap cap
;
144 struct acpi_video_bus_flags flags
;
145 struct list_head video_device_list
;
146 struct mutex device_list_lock
; /* protects video_device_list */
147 struct proc_dir_entry
*dir
;
148 struct input_dev
*input
;
149 char phys
[32]; /* for input device */
152 struct acpi_video_device_flags
{
162 struct acpi_video_device_cap
{
163 u8 _ADR
:1; /*Return the unique ID */
164 u8 _BCL
:1; /*Query list of brightness control levels supported */
165 u8 _BCM
:1; /*Set the brightness level */
166 u8 _BQC
:1; /* Get current brightness level */
167 u8 _DDC
:1; /*Return the EDID for this device */
168 u8 _DCS
:1; /*Return status of output device */
169 u8 _DGS
:1; /*Query graphics state */
170 u8 _DSS
:1; /*Device state set */
173 struct acpi_video_device_brightness
{
179 struct acpi_video_device
{
180 unsigned long device_id
;
181 struct acpi_video_device_flags flags
;
182 struct acpi_video_device_cap cap
;
183 struct list_head entry
;
184 struct acpi_video_bus
*video
;
185 struct acpi_device
*dev
;
186 struct acpi_video_device_brightness
*brightness
;
187 struct backlight_device
*backlight
;
188 struct thermal_cooling_device
*cdev
;
189 struct output_device
*output_dev
;
193 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
194 static struct file_operations acpi_video_bus_info_fops
= {
195 .open
= acpi_video_bus_info_open_fs
,
198 .release
= single_release
,
201 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
202 static struct file_operations acpi_video_bus_ROM_fops
= {
203 .open
= acpi_video_bus_ROM_open_fs
,
206 .release
= single_release
,
209 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
211 static struct file_operations acpi_video_bus_POST_info_fops
= {
212 .open
= acpi_video_bus_POST_info_open_fs
,
215 .release
= single_release
,
218 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
219 static struct file_operations acpi_video_bus_POST_fops
= {
220 .open
= acpi_video_bus_POST_open_fs
,
223 .release
= single_release
,
226 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
227 static struct file_operations acpi_video_bus_DOS_fops
= {
228 .open
= acpi_video_bus_DOS_open_fs
,
231 .release
= single_release
,
235 static int acpi_video_device_info_open_fs(struct inode
*inode
,
237 static struct file_operations acpi_video_device_info_fops
= {
238 .open
= acpi_video_device_info_open_fs
,
241 .release
= single_release
,
244 static int acpi_video_device_state_open_fs(struct inode
*inode
,
246 static struct file_operations acpi_video_device_state_fops
= {
247 .open
= acpi_video_device_state_open_fs
,
250 .release
= single_release
,
253 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
255 static struct file_operations acpi_video_device_brightness_fops
= {
256 .open
= acpi_video_device_brightness_open_fs
,
259 .release
= single_release
,
262 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
264 static struct file_operations acpi_video_device_EDID_fops
= {
265 .open
= acpi_video_device_EDID_open_fs
,
268 .release
= single_release
,
271 static char device_decode
[][30] = {
272 "motherboard VGA device",
278 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
279 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
280 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
281 struct acpi_video_device
*device
);
282 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
283 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
285 static int acpi_video_device_lcd_get_level_current(
286 struct acpi_video_device
*device
,
287 unsigned long *level
);
288 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
289 u32 level_current
, u32 event
);
290 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
292 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
293 unsigned long *state
);
294 static int acpi_video_output_get(struct output_device
*od
);
295 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
297 /*backlight device sysfs support*/
298 static int acpi_video_get_brightness(struct backlight_device
*bd
)
300 unsigned long cur_level
;
302 struct acpi_video_device
*vd
=
303 (struct acpi_video_device
*)bl_get_data(bd
);
304 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
305 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
306 if (vd
->brightness
->levels
[i
] == cur_level
)
307 /* The first two entries are special - see page 575
308 of the ACPI spec 3.0 */
314 static int acpi_video_set_brightness(struct backlight_device
*bd
)
316 int request_level
= bd
->props
.brightness
+2;
317 struct acpi_video_device
*vd
=
318 (struct acpi_video_device
*)bl_get_data(bd
);
319 acpi_video_device_lcd_set_level(vd
,
320 vd
->brightness
->levels
[request_level
]);
324 static struct backlight_ops acpi_backlight_ops
= {
325 .get_brightness
= acpi_video_get_brightness
,
326 .update_status
= acpi_video_set_brightness
,
329 /*video output device sysfs support*/
330 static int acpi_video_output_get(struct output_device
*od
)
333 struct acpi_video_device
*vd
=
334 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
335 acpi_video_device_get_state(vd
, &state
);
339 static int acpi_video_output_set(struct output_device
*od
)
341 unsigned long state
= od
->request_state
;
342 struct acpi_video_device
*vd
=
343 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
344 return acpi_video_device_set_state(vd
, state
);
347 static struct output_properties acpi_output_properties
= {
348 .set_state
= acpi_video_output_set
,
349 .get_status
= acpi_video_output_get
,
353 /* thermal cooling device callbacks */
354 static int video_get_max_state(struct thermal_cooling_device
*cdev
, char *buf
)
356 struct acpi_device
*device
= cdev
->devdata
;
357 struct acpi_video_device
*video
= acpi_driver_data(device
);
359 return sprintf(buf
, "%d\n", video
->brightness
->count
- 3);
362 static int video_get_cur_state(struct thermal_cooling_device
*cdev
, char *buf
)
364 struct acpi_device
*device
= cdev
->devdata
;
365 struct acpi_video_device
*video
= acpi_driver_data(device
);
369 acpi_video_device_lcd_get_level_current(video
, &level
);
370 for (state
= 2; state
< video
->brightness
->count
; state
++)
371 if (level
== video
->brightness
->levels
[state
])
372 return sprintf(buf
, "%d\n",
373 video
->brightness
->count
- state
- 1);
379 video_set_cur_state(struct thermal_cooling_device
*cdev
, unsigned int state
)
381 struct acpi_device
*device
= cdev
->devdata
;
382 struct acpi_video_device
*video
= acpi_driver_data(device
);
385 if ( state
>= video
->brightness
->count
- 2)
388 state
= video
->brightness
->count
- state
;
389 level
= video
->brightness
->levels
[state
-1];
390 return acpi_video_device_lcd_set_level(video
, level
);
393 static struct thermal_cooling_device_ops video_cooling_ops
= {
394 .get_max_state
= video_get_max_state
,
395 .get_cur_state
= video_get_cur_state
,
396 .set_cur_state
= video_set_cur_state
,
399 /* --------------------------------------------------------------------------
401 -------------------------------------------------------------------------- */
406 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long *state
)
410 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
416 acpi_video_device_get_state(struct acpi_video_device
*device
,
417 unsigned long *state
)
421 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
427 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
430 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
431 struct acpi_object_list args
= { 1, &arg0
};
435 arg0
.integer
.value
= state
;
436 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
442 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
443 union acpi_object
**levels
)
446 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
447 union acpi_object
*obj
;
452 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
453 if (!ACPI_SUCCESS(status
))
455 obj
= (union acpi_object
*)buffer
.pointer
;
456 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
457 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
467 kfree(buffer
.pointer
);
473 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
476 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
477 struct acpi_object_list args
= { 1, &arg0
};
480 arg0
.integer
.value
= level
;
482 if (device
->cap
._BCM
)
483 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
485 device
->brightness
->curr
= level
;
490 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
491 unsigned long *level
)
493 if (device
->cap
._BQC
)
494 return acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
,
496 *level
= device
->brightness
->curr
;
501 acpi_video_device_EDID(struct acpi_video_device
*device
,
502 union acpi_object
**edid
, ssize_t length
)
505 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
506 union acpi_object
*obj
;
507 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
508 struct acpi_object_list args
= { 1, &arg0
};
516 arg0
.integer
.value
= 1;
517 else if (length
== 256)
518 arg0
.integer
.value
= 2;
522 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
523 if (ACPI_FAILURE(status
))
526 obj
= buffer
.pointer
;
528 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
531 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
542 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
546 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
547 struct acpi_object_list args
= { 1, &arg0
};
550 arg0
.integer
.value
= option
;
552 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
553 if (ACPI_SUCCESS(status
))
554 status
= tmp
? (-EINVAL
) : (AE_OK
);
560 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long *id
)
564 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
570 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
571 unsigned long *options
)
575 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
583 * video : video bus device pointer
585 * 0. The system BIOS should NOT automatically switch(toggle)
586 * the active display output.
587 * 1. The system BIOS should automatically switch (toggle) the
588 * active display output. No switch event.
589 * 2. The _DGS value should be locked.
590 * 3. The system BIOS should not automatically switch (toggle) the
591 * active display output, but instead generate the display switch
594 * 0. The system BIOS should automatically control the brightness level
595 * of the LCD when the power changes from AC to DC
596 * 1. The system BIOS should NOT automatically control the brightness
597 * level of the LCD when the power changes from AC to DC.
603 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
605 acpi_integer status
= 0;
606 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
607 struct acpi_object_list args
= { 1, &arg0
};
610 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
614 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
615 video
->dos_setting
= arg0
.integer
.value
;
616 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
624 * device : video output device (LCD, CRT, ..)
629 * Find out all required AML methods defined under the output
633 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
635 acpi_handle h_dummy1
;
638 union acpi_object
*obj
= NULL
;
639 struct acpi_video_device_brightness
*br
= NULL
;
642 memset(&device
->cap
, 0, sizeof(device
->cap
));
644 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
645 device
->cap
._ADR
= 1;
647 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
648 device
->cap
._BCL
= 1;
650 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
651 device
->cap
._BCM
= 1;
653 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
654 device
->cap
._BQC
= 1;
655 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
656 device
->cap
._DDC
= 1;
658 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
659 device
->cap
._DCS
= 1;
661 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
662 device
->cap
._DGS
= 1;
664 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
665 device
->cap
._DSS
= 1;
668 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
670 if (obj
->package
.count
>= 2) {
672 union acpi_object
*o
;
674 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
676 printk(KERN_ERR
"can't allocate memory\n");
678 br
->levels
= kmalloc(obj
->package
.count
*
679 sizeof *(br
->levels
), GFP_KERNEL
);
683 for (i
= 0; i
< obj
->package
.count
; i
++) {
684 o
= (union acpi_object
*)&obj
->package
.
686 if (o
->type
!= ACPI_TYPE_INTEGER
) {
687 printk(KERN_ERR PREFIX
"Invalid data\n");
690 br
->levels
[count
] = (u32
) o
->integer
.value
;
692 if (br
->levels
[count
] > max_level
)
693 max_level
= br
->levels
[count
];
702 device
->brightness
= br
;
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
704 "found %d brightness levels\n",
711 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available LCD brightness level\n"));
716 <<<<<<< HEAD
:drivers
/acpi
/video
.c
717 if (device
->cap
._BCL
&& device
->cap
._BCM
&& device
->cap
._BQC
&& max_level
> 0){
719 if (device
->cap
._BCL
&& device
->cap
._BCM
&& max_level
> 0) {
720 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/video
.c
722 static int count
= 0;
724 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
728 sprintf(name
, "acpi_video%d", count
++);
729 device
->backlight
= backlight_device_register(name
,
730 NULL
, device
, &acpi_backlight_ops
);
731 device
->backlight
->props
.max_brightness
= device
->brightness
->count
-3;
732 device
->backlight
->props
.brightness
= acpi_video_get_brightness(device
->backlight
);
733 backlight_update_status(device
->backlight
);
736 device
->cdev
= thermal_cooling_device_register("LCD",
737 device
->dev
, &video_cooling_ops
);
738 <<<<<<< HEAD
:drivers
/acpi
/video
.c
740 if (IS_ERR(device
->cdev
))
743 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/video
.c
745 printk(KERN_INFO PREFIX
746 "%s is registered as cooling_device%d\n",
747 device
->dev
->dev
.bus_id
, device
->cdev
->id
);
748 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
749 &device
->cdev
->device
.kobj
,
752 printk(KERN_ERR PREFIX
"Create sysfs link\n");
753 result
= sysfs_create_link(&device
->cdev
->device
.kobj
,
754 &device
->dev
->dev
.kobj
,
757 printk(KERN_ERR PREFIX
"Create sysfs link\n");
760 if (device
->cap
._DCS
&& device
->cap
._DSS
){
761 static int count
= 0;
763 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
766 sprintf(name
, "acpi_video%d", count
++);
767 device
->output_dev
= video_output_register(name
,
768 NULL
, device
, &acpi_output_properties
);
776 * device : video output device (VGA)
781 * Find out all required AML methods defined under the video bus device.
784 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
786 acpi_handle h_dummy1
;
788 memset(&video
->cap
, 0, sizeof(video
->cap
));
789 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
792 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
795 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
798 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
801 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
804 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
810 * Check whether the video bus device has required AML method to
811 * support the desired features
814 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
816 acpi_status status
= -ENOENT
;
817 <<<<<<< HEAD
:drivers
/acpi
/video
.c
820 struct acpi_device
*device
;
823 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/video
.c
828 <<<<<<< HEAD
:drivers
/acpi
/video
.c
829 device
= video
->device
;
832 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
834 if (!ACPI_SUCCESS(status
))
837 /* We need to attempt to determine whether the _ADR refers to a
838 PCI device or not. There's no terribly good way to do this,
839 so the best we can hope for is to assume that there'll never
840 be a video device in the host bridge */
841 if (device_id
>= 0x10000) {
842 /* It looks like a PCI device. Does it exist? */
843 dev
= acpi_get_physical_device(device
->handle
);
845 /* It doesn't look like a PCI device. Does its parent
848 if (acpi_get_parent(device
->handle
, &phandle
))
850 dev
= acpi_get_physical_device(phandle
);
857 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/video
.c
858 /* Since there is no HID, CID and so on for VGA driver, we have
859 * to check well known required nodes.
862 /* Does this device support video switching? */
863 if (video
->cap
._DOS
) {
864 video
->flags
.multihead
= 1;
868 /* Does this device support retrieving a video ROM? */
869 if (video
->cap
._ROM
) {
870 video
->flags
.rom
= 1;
874 /* Does this device support configuring which video device to POST? */
875 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
876 video
->flags
.post
= 1;
883 /* --------------------------------------------------------------------------
885 -------------------------------------------------------------------------- */
887 static struct proc_dir_entry
*acpi_video_dir
;
891 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
893 struct acpi_video_device
*dev
= seq
->private;
899 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
900 seq_printf(seq
, "type: ");
902 seq_printf(seq
, "CRT\n");
903 else if (dev
->flags
.lcd
)
904 seq_printf(seq
, "LCD\n");
905 else if (dev
->flags
.tvout
)
906 seq_printf(seq
, "TVOUT\n");
907 else if (dev
->flags
.dvi
)
908 seq_printf(seq
, "DVI\n");
910 seq_printf(seq
, "UNKNOWN\n");
912 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
919 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
921 return single_open(file
, acpi_video_device_info_seq_show
,
925 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
928 struct acpi_video_device
*dev
= seq
->private;
935 status
= acpi_video_device_get_state(dev
, &state
);
936 seq_printf(seq
, "state: ");
937 if (ACPI_SUCCESS(status
))
938 seq_printf(seq
, "0x%02lx\n", state
);
940 seq_printf(seq
, "<not supported>\n");
942 status
= acpi_video_device_query(dev
, &state
);
943 seq_printf(seq
, "query: ");
944 if (ACPI_SUCCESS(status
))
945 seq_printf(seq
, "0x%02lx\n", state
);
947 seq_printf(seq
, "<not supported>\n");
954 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
956 return single_open(file
, acpi_video_device_state_seq_show
,
961 acpi_video_device_write_state(struct file
*file
,
962 const char __user
* buffer
,
963 size_t count
, loff_t
* data
)
966 struct seq_file
*m
= file
->private_data
;
967 struct acpi_video_device
*dev
= m
->private;
968 char str
[12] = { 0 };
972 if (!dev
|| count
+ 1 > sizeof str
)
975 if (copy_from_user(str
, buffer
, count
))
979 state
= simple_strtoul(str
, NULL
, 0);
980 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
982 status
= acpi_video_device_set_state(dev
, state
);
991 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
993 struct acpi_video_device
*dev
= seq
->private;
997 if (!dev
|| !dev
->brightness
) {
998 seq_printf(seq
, "<not supported>\n");
1002 seq_printf(seq
, "levels: ");
1003 for (i
= 0; i
< dev
->brightness
->count
; i
++)
1004 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
1005 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
1011 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
1013 return single_open(file
, acpi_video_device_brightness_seq_show
,
1018 acpi_video_device_write_brightness(struct file
*file
,
1019 const char __user
* buffer
,
1020 size_t count
, loff_t
* data
)
1022 struct seq_file
*m
= file
->private_data
;
1023 struct acpi_video_device
*dev
= m
->private;
1024 char str
[5] = { 0 };
1025 unsigned int level
= 0;
1029 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
1032 if (copy_from_user(str
, buffer
, count
))
1036 level
= simple_strtoul(str
, NULL
, 0);
1041 /* validate through the list of available levels */
1042 for (i
= 0; i
< dev
->brightness
->count
; i
++)
1043 if (level
== dev
->brightness
->levels
[i
]) {
1045 (acpi_video_device_lcd_set_level(dev
, level
)))
1046 dev
->brightness
->curr
= level
;
1053 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
1055 struct acpi_video_device
*dev
= seq
->private;
1058 union acpi_object
*edid
= NULL
;
1064 status
= acpi_video_device_EDID(dev
, &edid
, 128);
1065 if (ACPI_FAILURE(status
)) {
1066 status
= acpi_video_device_EDID(dev
, &edid
, 256);
1069 if (ACPI_FAILURE(status
)) {
1073 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
1074 for (i
= 0; i
< edid
->buffer
.length
; i
++)
1075 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
1080 seq_printf(seq
, "<not supported>\n");
1088 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
1090 return single_open(file
, acpi_video_device_EDID_seq_show
,
1094 static int acpi_video_device_add_fs(struct acpi_device
*device
)
1096 struct proc_dir_entry
*entry
= NULL
;
1097 struct acpi_video_device
*vid_dev
;
1103 vid_dev
= acpi_driver_data(device
);
1107 if (!acpi_device_dir(device
)) {
1108 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1109 vid_dev
->video
->dir
);
1110 if (!acpi_device_dir(device
))
1112 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1116 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1120 entry
->proc_fops
= &acpi_video_device_info_fops
;
1121 entry
->data
= acpi_driver_data(device
);
1122 entry
->owner
= THIS_MODULE
;
1127 create_proc_entry("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1128 acpi_device_dir(device
));
1132 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
1133 entry
->proc_fops
= &acpi_video_device_state_fops
;
1134 entry
->data
= acpi_driver_data(device
);
1135 entry
->owner
= THIS_MODULE
;
1138 /* 'brightness' [R/W] */
1140 create_proc_entry("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1141 acpi_device_dir(device
));
1145 acpi_video_device_brightness_fops
.write
= acpi_video_device_write_brightness
;
1146 entry
->proc_fops
= &acpi_video_device_brightness_fops
;
1147 entry
->data
= acpi_driver_data(device
);
1148 entry
->owner
= THIS_MODULE
;
1152 entry
= create_proc_entry("EDID", S_IRUGO
, acpi_device_dir(device
));
1156 entry
->proc_fops
= &acpi_video_device_EDID_fops
;
1157 entry
->data
= acpi_driver_data(device
);
1158 entry
->owner
= THIS_MODULE
;
1164 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1166 struct acpi_video_device
*vid_dev
;
1168 vid_dev
= acpi_driver_data(device
);
1169 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1172 if (acpi_device_dir(device
)) {
1173 remove_proc_entry("info", acpi_device_dir(device
));
1174 remove_proc_entry("state", acpi_device_dir(device
));
1175 remove_proc_entry("brightness", acpi_device_dir(device
));
1176 remove_proc_entry("EDID", acpi_device_dir(device
));
1177 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1178 acpi_device_dir(device
) = NULL
;
1185 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1187 struct acpi_video_bus
*video
= seq
->private;
1193 seq_printf(seq
, "Switching heads: %s\n",
1194 video
->flags
.multihead
? "yes" : "no");
1195 seq_printf(seq
, "Video ROM: %s\n",
1196 video
->flags
.rom
? "yes" : "no");
1197 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1198 video
->flags
.post
? "yes" : "no");
1204 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1206 return single_open(file
, acpi_video_bus_info_seq_show
,
1210 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1212 struct acpi_video_bus
*video
= seq
->private;
1218 <<<<<<< HEAD
:drivers
/acpi
/video
.c
1219 printk(KERN_INFO PREFIX
"Please implement %s\n", __FUNCTION__
);
1221 printk(KERN_INFO PREFIX
"Please implement %s\n", __func__
);
1222 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/video
.c
1223 seq_printf(seq
, "<TODO>\n");
1229 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1231 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1234 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1236 struct acpi_video_bus
*video
= seq
->private;
1237 unsigned long options
;
1244 status
= acpi_video_bus_POST_options(video
, &options
);
1245 if (ACPI_SUCCESS(status
)) {
1246 if (!(options
& 1)) {
1247 printk(KERN_WARNING PREFIX
1248 "The motherboard VGA device is not listed as a possible POST device.\n");
1249 printk(KERN_WARNING PREFIX
1250 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1252 printk("%lx\n", options
);
1253 seq_printf(seq
, "can POST: <integrated video>");
1255 seq_printf(seq
, " <PCI video>");
1257 seq_printf(seq
, " <AGP video>");
1258 seq_putc(seq
, '\n');
1260 seq_printf(seq
, "<not supported>\n");
1266 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1268 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1272 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1274 struct acpi_video_bus
*video
= seq
->private;
1282 status
= acpi_video_bus_get_POST(video
, &id
);
1283 if (!ACPI_SUCCESS(status
)) {
1284 seq_printf(seq
, "<not supported>\n");
1287 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1293 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1295 struct acpi_video_bus
*video
= seq
->private;
1298 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1303 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1305 return single_open(file
, acpi_video_bus_POST_seq_show
,
1309 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1311 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1315 acpi_video_bus_write_POST(struct file
*file
,
1316 const char __user
* buffer
,
1317 size_t count
, loff_t
* data
)
1320 struct seq_file
*m
= file
->private_data
;
1321 struct acpi_video_bus
*video
= m
->private;
1322 char str
[12] = { 0 };
1323 unsigned long opt
, options
;
1326 if (!video
|| count
+ 1 > sizeof str
)
1329 status
= acpi_video_bus_POST_options(video
, &options
);
1330 if (!ACPI_SUCCESS(status
))
1333 if (copy_from_user(str
, buffer
, count
))
1337 opt
= strtoul(str
, NULL
, 0);
1341 /* just in case an OEM 'forgot' the motherboard... */
1344 if (options
& (1ul << opt
)) {
1345 status
= acpi_video_bus_set_POST(video
, opt
);
1346 if (!ACPI_SUCCESS(status
))
1355 acpi_video_bus_write_DOS(struct file
*file
,
1356 const char __user
* buffer
,
1357 size_t count
, loff_t
* data
)
1360 struct seq_file
*m
= file
->private_data
;
1361 struct acpi_video_bus
*video
= m
->private;
1362 char str
[12] = { 0 };
1366 if (!video
|| count
+ 1 > sizeof str
)
1369 if (copy_from_user(str
, buffer
, count
))
1373 opt
= strtoul(str
, NULL
, 0);
1377 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1379 if (!ACPI_SUCCESS(status
))
1385 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1387 <<<<<<< HEAD
:drivers
/acpi
/video
.c
1391 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/video
.c
1392 struct proc_dir_entry
*entry
= NULL
;
1393 struct acpi_video_bus
*video
;
1394 <<<<<<< HEAD
:drivers
/acpi
/video
.c
1398 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1400 if (!ACPI_SUCCESS(status
))
1403 /* We need to attempt to determine whether the _ADR refers to a
1404 PCI device or not. There's no terribly good way to do this,
1405 so the best we can hope for is to assume that there'll never
1406 be a video device in the host bridge */
1407 if (device_id
>= 0x10000) {
1408 /* It looks like a PCI device. Does it exist? */
1409 dev
= acpi_get_physical_device(device
->handle
);
1411 /* It doesn't look like a PCI device. Does its parent
1413 acpi_handle phandle
;
1414 if (acpi_get_parent(device
->handle
, &phandle
))
1416 dev
= acpi_get_physical_device(phandle
);
1423 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/acpi
/video
.c
1426 video
= acpi_driver_data(device
);
1428 if (!acpi_device_dir(device
)) {
1429 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1431 if (!acpi_device_dir(device
))
1433 video
->dir
= acpi_device_dir(device
);
1434 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1438 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1442 entry
->proc_fops
= &acpi_video_bus_info_fops
;
1443 entry
->data
= acpi_driver_data(device
);
1444 entry
->owner
= THIS_MODULE
;
1448 entry
= create_proc_entry("ROM", S_IRUGO
, acpi_device_dir(device
));
1452 entry
->proc_fops
= &acpi_video_bus_ROM_fops
;
1453 entry
->data
= acpi_driver_data(device
);
1454 entry
->owner
= THIS_MODULE
;
1457 /* 'POST_info' [R] */
1459 create_proc_entry("POST_info", S_IRUGO
, acpi_device_dir(device
));
1463 entry
->proc_fops
= &acpi_video_bus_POST_info_fops
;
1464 entry
->data
= acpi_driver_data(device
);
1465 entry
->owner
= THIS_MODULE
;
1470 create_proc_entry("POST", S_IFREG
| S_IRUGO
| S_IRUSR
,
1471 acpi_device_dir(device
));
1475 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1476 entry
->proc_fops
= &acpi_video_bus_POST_fops
;
1477 entry
->data
= acpi_driver_data(device
);
1478 entry
->owner
= THIS_MODULE
;
1483 create_proc_entry("DOS", S_IFREG
| S_IRUGO
| S_IRUSR
,
1484 acpi_device_dir(device
));
1488 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1489 entry
->proc_fops
= &acpi_video_bus_DOS_fops
;
1490 entry
->data
= acpi_driver_data(device
);
1491 entry
->owner
= THIS_MODULE
;
1497 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1499 struct acpi_video_bus
*video
;
1502 video
= acpi_driver_data(device
);
1504 if (acpi_device_dir(device
)) {
1505 remove_proc_entry("info", acpi_device_dir(device
));
1506 remove_proc_entry("ROM", acpi_device_dir(device
));
1507 remove_proc_entry("POST_info", acpi_device_dir(device
));
1508 remove_proc_entry("POST", acpi_device_dir(device
));
1509 remove_proc_entry("DOS", acpi_device_dir(device
));
1510 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1511 acpi_device_dir(device
) = NULL
;
1517 /* --------------------------------------------------------------------------
1519 -------------------------------------------------------------------------- */
1521 /* device interface */
1522 static struct acpi_video_device_attrib
*
1523 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1527 for(count
= 0; count
< video
->attached_count
; count
++)
1528 if((video
->attached_array
[count
].value
.int_val
& 0xffff) == device_id
)
1529 return &(video
->attached_array
[count
].value
.attrib
);
1534 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1535 struct acpi_video_bus
*video
)
1537 unsigned long device_id
;
1539 struct acpi_video_device
*data
;
1540 struct acpi_video_device_attrib
* attribute
;
1542 if (!device
|| !video
)
1546 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1547 if (ACPI_SUCCESS(status
)) {
1549 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1553 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1554 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1555 acpi_driver_data(device
) = data
;
1557 data
->device_id
= device_id
;
1558 data
->video
= video
;
1561 attribute
= acpi_video_get_device_attr(video
, device_id
);
1563 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1564 switch (attribute
->display_type
) {
1565 case ACPI_VIDEO_DISPLAY_CRT
:
1566 data
->flags
.crt
= 1;
1568 case ACPI_VIDEO_DISPLAY_TV
:
1569 data
->flags
.tvout
= 1;
1571 case ACPI_VIDEO_DISPLAY_DVI
:
1572 data
->flags
.dvi
= 1;
1574 case ACPI_VIDEO_DISPLAY_LCD
:
1575 data
->flags
.lcd
= 1;
1578 data
->flags
.unknown
= 1;
1581 if(attribute
->bios_can_detect
)
1582 data
->flags
.bios
= 1;
1584 data
->flags
.unknown
= 1;
1586 acpi_video_device_bind(video
, data
);
1587 acpi_video_device_find_cap(data
);
1589 status
= acpi_install_notify_handler(device
->handle
,
1591 acpi_video_device_notify
,
1593 if (ACPI_FAILURE(status
)) {
1594 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1595 "Error installing notify handler\n"));
1596 if(data
->brightness
)
1597 kfree(data
->brightness
->levels
);
1598 kfree(data
->brightness
);
1603 mutex_lock(&video
->device_list_lock
);
1604 list_add_tail(&data
->entry
, &video
->video_device_list
);
1605 mutex_unlock(&video
->device_list_lock
);
1607 acpi_video_device_add_fs(device
);
1617 * video : video bus device
1622 * Enumerate the video device list of the video bus,
1623 * bind the ids with the corresponding video devices
1624 * under the video bus.
1627 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1629 struct acpi_video_device
*dev
;
1631 mutex_lock(&video
->device_list_lock
);
1633 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1634 acpi_video_device_bind(video
, dev
);
1636 mutex_unlock(&video
->device_list_lock
);
1641 * video : video bus device
1642 * device : video output device under the video
1648 * Bind the ids with the corresponding video devices
1649 * under the video bus.
1653 acpi_video_device_bind(struct acpi_video_bus
*video
,
1654 struct acpi_video_device
*device
)
1658 #define IDS_VAL(i) video->attached_array[i].value.int_val
1659 #define IDS_BIND(i) video->attached_array[i].bind_info
1661 for (i
= 0; IDS_VAL(i
) != ACPI_VIDEO_HEAD_INVALID
&&
1662 i
< video
->attached_count
; i
++) {
1663 if (device
->device_id
== (IDS_VAL(i
) & 0xffff)) {
1664 IDS_BIND(i
) = device
;
1665 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1674 * video : video bus device
1679 * Call _DOD to enumerate all devices attached to display adapter
1683 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1688 struct acpi_video_enumerated_device
*active_device_list
;
1689 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1690 union acpi_object
*dod
= NULL
;
1691 union acpi_object
*obj
;
1693 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1694 if (!ACPI_SUCCESS(status
)) {
1695 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1699 dod
= buffer
.pointer
;
1700 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1701 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1706 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1707 dod
->package
.count
));
1709 active_device_list
= kmalloc((1 +
1710 dod
->package
.count
) *
1712 acpi_video_enumerated_device
),
1715 if (!active_device_list
) {
1721 for (i
= 0; i
< dod
->package
.count
; i
++) {
1722 obj
= &dod
->package
.elements
[i
];
1724 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1725 printk(KERN_ERR PREFIX
"Invalid _DOD data\n");
1726 active_device_list
[i
].value
.int_val
=
1727 ACPI_VIDEO_HEAD_INVALID
;
1729 active_device_list
[i
].value
.int_val
= obj
->integer
.value
;
1730 active_device_list
[i
].bind_info
= NULL
;
1731 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1732 (int)obj
->integer
.value
));
1735 active_device_list
[count
].value
.int_val
= ACPI_VIDEO_HEAD_END
;
1737 kfree(video
->attached_array
);
1739 video
->attached_array
= active_device_list
;
1740 video
->attached_count
= count
;
1742 kfree(buffer
.pointer
);
1747 acpi_video_get_next_level(struct acpi_video_device
*device
,
1748 u32 level_current
, u32 event
)
1750 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1751 max
= max_below
= 0;
1752 min
= min_above
= 255;
1753 /* Find closest level to level_current */
1754 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1755 l
= device
->brightness
->levels
[i
];
1756 if (abs(l
- level_current
) < abs(delta
)) {
1757 delta
= l
- level_current
;
1762 /* Ajust level_current to closest available level */
1763 level_current
+= delta
;
1764 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1765 l
= device
->brightness
->levels
[i
];
1770 if (l
< min_above
&& l
> level_current
)
1772 if (l
> max_below
&& l
< level_current
)
1777 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1778 return (level_current
< max
) ? min_above
: min
;
1779 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1780 return (level_current
< max
) ? min_above
: max
;
1781 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1782 return (level_current
> min
) ? max_below
: min
;
1783 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1784 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1787 return level_current
;
1792 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1794 unsigned long level_current
, level_next
;
1795 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1796 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1797 acpi_video_device_lcd_set_level(device
, level_next
);
1801 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1802 struct acpi_device
*device
)
1805 struct acpi_device
*dev
;
1807 acpi_video_device_enumerate(video
);
1809 list_for_each_entry(dev
, &device
->children
, node
) {
1811 status
= acpi_video_bus_get_one_device(dev
, video
);
1812 if (ACPI_FAILURE(status
)) {
1813 ACPI_EXCEPTION((AE_INFO
, status
, "Cant attach device"));
1820 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1823 struct acpi_video_bus
*video
;
1826 if (!device
|| !device
->video
)
1829 video
= device
->video
;
1831 acpi_video_device_remove_fs(device
->dev
);
1833 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1835 acpi_video_device_notify
);
1836 backlight_device_unregister(device
->backlight
);
1838 sysfs_remove_link(&device
->dev
->dev
.kobj
,
1840 sysfs_remove_link(&device
->cdev
->device
.kobj
,
1842 thermal_cooling_device_unregister(device
->cdev
);
1843 device
->cdev
= NULL
;
1845 video_output_unregister(device
->output_dev
);
1850 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1853 struct acpi_video_device
*dev
, *next
;
1855 mutex_lock(&video
->device_list_lock
);
1857 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1859 status
= acpi_video_bus_put_one_device(dev
);
1860 if (ACPI_FAILURE(status
))
1861 printk(KERN_WARNING PREFIX
1862 "hhuuhhuu bug in acpi video driver.\n");
1864 if (dev
->brightness
) {
1865 kfree(dev
->brightness
->levels
);
1866 kfree(dev
->brightness
);
1868 list_del(&dev
->entry
);
1872 mutex_unlock(&video
->device_list_lock
);
1877 /* acpi_video interface */
1879 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1881 return acpi_video_bus_DOS(video
, 0, 0);
1884 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1886 return acpi_video_bus_DOS(video
, 0, 1);
1889 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1891 struct acpi_video_bus
*video
= data
;
1892 struct acpi_device
*device
= NULL
;
1893 struct input_dev
*input
;
1899 device
= video
->device
;
1900 input
= video
->input
;
1903 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1904 * most likely via hotkey. */
1905 acpi_bus_generate_proc_event(device
, event
, 0);
1906 keycode
= KEY_SWITCHVIDEOMODE
;
1909 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1911 acpi_video_device_enumerate(video
);
1912 acpi_video_device_rebind(video
);
1913 acpi_bus_generate_proc_event(device
, event
, 0);
1914 keycode
= KEY_SWITCHVIDEOMODE
;
1917 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1918 acpi_bus_generate_proc_event(device
, event
, 0);
1919 keycode
= KEY_SWITCHVIDEOMODE
;
1921 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1922 acpi_bus_generate_proc_event(device
, event
, 0);
1923 keycode
= KEY_VIDEO_NEXT
;
1925 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1926 acpi_bus_generate_proc_event(device
, event
, 0);
1927 keycode
= KEY_VIDEO_PREV
;
1931 keycode
= KEY_UNKNOWN
;
1932 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1933 "Unsupported event [0x%x]\n", event
));
1937 acpi_notifier_call_chain(device
, event
, 0);
1938 input_report_key(input
, keycode
, 1);
1940 input_report_key(input
, keycode
, 0);
1946 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1948 struct acpi_video_device
*video_device
= data
;
1949 struct acpi_device
*device
= NULL
;
1950 struct acpi_video_bus
*bus
;
1951 struct input_dev
*input
;
1957 device
= video_device
->dev
;
1958 bus
= video_device
->video
;
1962 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1963 if (brightness_switch_enabled
)
1964 acpi_video_switch_brightness(video_device
, event
);
1965 acpi_bus_generate_proc_event(device
, event
, 0);
1966 keycode
= KEY_BRIGHTNESS_CYCLE
;
1968 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1969 if (brightness_switch_enabled
)
1970 acpi_video_switch_brightness(video_device
, event
);
1971 acpi_bus_generate_proc_event(device
, event
, 0);
1972 keycode
= KEY_BRIGHTNESSUP
;
1974 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1975 if (brightness_switch_enabled
)
1976 acpi_video_switch_brightness(video_device
, event
);
1977 acpi_bus_generate_proc_event(device
, event
, 0);
1978 keycode
= KEY_BRIGHTNESSDOWN
;
1980 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1981 if (brightness_switch_enabled
)
1982 acpi_video_switch_brightness(video_device
, event
);
1983 acpi_bus_generate_proc_event(device
, event
, 0);
1984 keycode
= KEY_BRIGHTNESS_ZERO
;
1986 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1987 if (brightness_switch_enabled
)
1988 acpi_video_switch_brightness(video_device
, event
);
1989 acpi_bus_generate_proc_event(device
, event
, 0);
1990 keycode
= KEY_DISPLAY_OFF
;
1993 keycode
= KEY_UNKNOWN
;
1994 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1995 "Unsupported event [0x%x]\n", event
));
1999 acpi_notifier_call_chain(device
, event
, 0);
2000 input_report_key(input
, keycode
, 1);
2002 input_report_key(input
, keycode
, 0);
2008 static int instance
;
2009 static int acpi_video_resume(struct acpi_device
*device
)
2011 struct acpi_video_bus
*video
;
2012 struct acpi_video_device
*video_device
;
2015 if (!device
|| !acpi_driver_data(device
))
2018 video
= acpi_driver_data(device
);
2020 for (i
= 0; i
< video
->attached_count
; i
++) {
2021 video_device
= video
->attached_array
[i
].bind_info
;
2022 if (video_device
&& video_device
->backlight
)
2023 acpi_video_set_brightness(video_device
->backlight
);
2028 static int acpi_video_bus_add(struct acpi_device
*device
)
2031 struct acpi_video_bus
*video
;
2032 struct input_dev
*input
;
2035 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
2039 /* a hack to fix the duplicate name "VID" problem on T61 */
2040 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
2042 device
->pnp
.bus_id
[3] = '0' + instance
;
2046 video
->device
= device
;
2047 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
2048 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
2049 acpi_driver_data(device
) = video
;
2051 acpi_video_bus_find_cap(video
);
2052 error
= acpi_video_bus_check(video
);
2054 goto err_free_video
;
2056 error
= acpi_video_bus_add_fs(device
);
2058 goto err_free_video
;
2060 mutex_init(&video
->device_list_lock
);
2061 INIT_LIST_HEAD(&video
->video_device_list
);
2063 acpi_video_bus_get_devices(video
, device
);
2064 acpi_video_bus_start_devices(video
);
2066 status
= acpi_install_notify_handler(device
->handle
,
2068 acpi_video_bus_notify
, video
);
2069 if (ACPI_FAILURE(status
)) {
2070 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
2071 "Error installing notify handler\n"));
2073 goto err_stop_video
;
2076 video
->input
= input
= input_allocate_device();
2079 goto err_uninstall_notify
;
2082 snprintf(video
->phys
, sizeof(video
->phys
),
2083 "%s/video/input0", acpi_device_hid(video
->device
));
2085 input
->name
= acpi_device_name(video
->device
);
2086 input
->phys
= video
->phys
;
2087 input
->id
.bustype
= BUS_HOST
;
2088 input
->id
.product
= 0x06;
2089 input
->dev
.parent
= &device
->dev
;
2090 input
->evbit
[0] = BIT(EV_KEY
);
2091 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
2092 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
2093 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
2094 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
2095 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
2096 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
2097 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
2098 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
2099 set_bit(KEY_UNKNOWN
, input
->keybit
);
2101 error
= input_register_device(input
);
2103 goto err_free_input_dev
;
2105 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
2106 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
2107 video
->flags
.multihead
? "yes" : "no",
2108 video
->flags
.rom
? "yes" : "no",
2109 video
->flags
.post
? "yes" : "no");
2114 input_free_device(input
);
2115 err_uninstall_notify
:
2116 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
2117 acpi_video_bus_notify
);
2119 acpi_video_bus_stop_devices(video
);
2120 acpi_video_bus_put_devices(video
);
2121 kfree(video
->attached_array
);
2122 acpi_video_bus_remove_fs(device
);
2125 acpi_driver_data(device
) = NULL
;
2130 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2132 acpi_status status
= 0;
2133 struct acpi_video_bus
*video
= NULL
;
2136 if (!device
|| !acpi_driver_data(device
))
2139 video
= acpi_driver_data(device
);
2141 acpi_video_bus_stop_devices(video
);
2143 status
= acpi_remove_notify_handler(video
->device
->handle
,
2145 acpi_video_bus_notify
);
2147 acpi_video_bus_put_devices(video
);
2148 acpi_video_bus_remove_fs(device
);
2150 input_unregister_device(video
->input
);
2151 kfree(video
->attached_array
);
2157 static int __init
acpi_video_init(void)
2163 acpi_dbg_level = 0xFFFFFFFF;
2164 acpi_dbg_layer = 0x08000000;
2167 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2168 if (!acpi_video_dir
)
2170 acpi_video_dir
->owner
= THIS_MODULE
;
2172 result
= acpi_bus_register_driver(&acpi_video_bus
);
2174 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2181 static void __exit
acpi_video_exit(void)
2184 acpi_bus_unregister_driver(&acpi_video_bus
);
2186 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2191 module_init(acpi_video_init
);
2192 module_exit(acpi_video_exit
);