2 * video.c - ACPI Video Driver
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/input.h>
34 #include <linux/backlight.h>
35 #include <linux/thermal.h>
36 #include <linux/sort.h>
37 #include <linux/pci.h>
38 #include <linux/pci_ids.h>
39 #include <linux/slab.h>
40 #include <asm/uaccess.h>
41 #include <linux/dmi.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
44 #include <linux/suspend.h>
45 #include <acpi/video.h>
49 #define PREFIX "ACPI: "
51 #define ACPI_VIDEO_BUS_NAME "Video Bus"
52 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
53 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
54 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
55 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
56 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
57 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
59 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
60 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
61 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
62 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
63 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
65 #define MAX_NAME_LEN 20
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static bool brightness_switch_enabled
= 1;
75 module_param(brightness_switch_enabled
, bool, 0644);
78 * By default, we don't allow duplicate ACPI video bus devices
79 * under the same VGA controller
81 static bool allow_duplicates
;
82 module_param(allow_duplicates
, bool, 0644);
85 * Some BIOSes claim they use minimum backlight at boot,
86 * and this may bring dimming screen after boot
88 static bool use_bios_initial_backlight
= 1;
89 module_param(use_bios_initial_backlight
, bool, 0644);
91 static int register_count
;
92 static struct mutex video_list_lock
;
93 static struct list_head video_bus_head
;
94 static int acpi_video_bus_add(struct acpi_device
*device
);
95 static int acpi_video_bus_remove(struct acpi_device
*device
);
96 static void acpi_video_bus_notify(struct acpi_device
*device
, u32 event
);
98 static const struct acpi_device_id video_device_ids
[] = {
102 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
104 static struct acpi_driver acpi_video_bus
= {
106 .class = ACPI_VIDEO_CLASS
,
107 .ids
= video_device_ids
,
109 .add
= acpi_video_bus_add
,
110 .remove
= acpi_video_bus_remove
,
111 .notify
= acpi_video_bus_notify
,
115 struct acpi_video_bus_flags
{
116 u8 multihead
:1; /* can switch video heads */
117 u8 rom
:1; /* can retrieve a video rom */
118 u8 post
:1; /* can configure the head to */
122 struct acpi_video_bus_cap
{
123 u8 _DOS
:1; /* Enable/Disable output switching */
124 u8 _DOD
:1; /* Enumerate all devices attached to display adapter */
125 u8 _ROM
:1; /* Get ROM Data */
126 u8 _GPD
:1; /* Get POST Device */
127 u8 _SPD
:1; /* Set POST Device */
128 u8 _VPO
:1; /* Video POST Options */
132 struct acpi_video_device_attrib
{
133 u32 display_index
:4; /* A zero-based instance of the Display */
134 u32 display_port_attachment
:4; /* This field differentiates the display type */
135 u32 display_type
:4; /* Describe the specific type in use */
136 u32 vendor_specific
:4; /* Chipset Vendor Specific */
137 u32 bios_can_detect
:1; /* BIOS can detect the device */
138 u32 depend_on_vga
:1; /* Non-VGA output device whose power is related to
140 u32 pipe_id
:3; /* For VGA multiple-head devices. */
141 u32 reserved
:10; /* Must be 0 */
142 u32 device_id_scheme
:1; /* Device ID Scheme */
145 struct acpi_video_enumerated_device
{
148 struct acpi_video_device_attrib attrib
;
150 struct acpi_video_device
*bind_info
;
153 struct acpi_video_bus
{
154 struct acpi_device
*device
;
156 struct acpi_video_enumerated_device
*attached_array
;
158 struct acpi_video_bus_cap cap
;
159 struct acpi_video_bus_flags flags
;
160 struct list_head video_device_list
;
161 struct mutex device_list_lock
; /* protects video_device_list */
162 struct list_head entry
;
163 struct input_dev
*input
;
164 char phys
[32]; /* for input device */
165 struct notifier_block pm_nb
;
168 struct acpi_video_device_flags
{
179 struct acpi_video_device_cap
{
180 u8 _ADR
:1; /* Return the unique ID */
181 u8 _BCL
:1; /* Query list of brightness control levels supported */
182 u8 _BCM
:1; /* Set the brightness level */
183 u8 _BQC
:1; /* Get current brightness level */
184 u8 _BCQ
:1; /* Some buggy BIOS uses _BCQ instead of _BQC */
185 u8 _DDC
:1; /* Return the EDID for this device */
188 struct acpi_video_brightness_flags
{
189 u8 _BCL_no_ac_battery_levels
:1; /* no AC/Battery levels in _BCL */
190 u8 _BCL_reversed
:1; /* _BCL package is in a reversed order */
191 u8 _BQC_use_index
:1; /* _BQC returns an index value */
194 struct acpi_video_device_brightness
{
198 struct acpi_video_brightness_flags flags
;
201 struct acpi_video_device
{
202 unsigned long device_id
;
203 struct acpi_video_device_flags flags
;
204 struct acpi_video_device_cap cap
;
205 struct list_head entry
;
206 struct acpi_video_bus
*video
;
207 struct acpi_device
*dev
;
208 struct acpi_video_device_brightness
*brightness
;
209 struct backlight_device
*backlight
;
210 struct thermal_cooling_device
*cooling_dev
;
213 static const char device_decode
[][30] = {
214 "motherboard VGA device",
220 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
221 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
222 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
223 struct acpi_video_device
*device
);
224 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
225 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
227 static int acpi_video_device_lcd_get_level_current(
228 struct acpi_video_device
*device
,
229 unsigned long long *level
, bool raw
);
230 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
231 u32 level_current
, u32 event
);
232 static int acpi_video_switch_brightness(struct acpi_video_device
*device
,
235 /* backlight device sysfs support */
236 static int acpi_video_get_brightness(struct backlight_device
*bd
)
238 unsigned long long cur_level
;
240 struct acpi_video_device
*vd
= bl_get_data(bd
);
242 if (acpi_video_device_lcd_get_level_current(vd
, &cur_level
, false))
244 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
245 if (vd
->brightness
->levels
[i
] == cur_level
)
247 * The first two entries are special - see page 575
248 * of the ACPI spec 3.0
255 static int acpi_video_set_brightness(struct backlight_device
*bd
)
257 int request_level
= bd
->props
.brightness
+ 2;
258 struct acpi_video_device
*vd
= bl_get_data(bd
);
260 return acpi_video_device_lcd_set_level(vd
,
261 vd
->brightness
->levels
[request_level
]);
264 static const struct backlight_ops acpi_backlight_ops
= {
265 .get_brightness
= acpi_video_get_brightness
,
266 .update_status
= acpi_video_set_brightness
,
269 /* thermal cooling device callbacks */
270 static int video_get_max_state(struct thermal_cooling_device
*cooling_dev
, unsigned
273 struct acpi_device
*device
= cooling_dev
->devdata
;
274 struct acpi_video_device
*video
= acpi_driver_data(device
);
276 *state
= video
->brightness
->count
- 3;
280 static int video_get_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned
283 struct acpi_device
*device
= cooling_dev
->devdata
;
284 struct acpi_video_device
*video
= acpi_driver_data(device
);
285 unsigned long long level
;
288 if (acpi_video_device_lcd_get_level_current(video
, &level
, false))
290 for (offset
= 2; offset
< video
->brightness
->count
; offset
++)
291 if (level
== video
->brightness
->levels
[offset
]) {
292 *state
= video
->brightness
->count
- offset
- 1;
300 video_set_cur_state(struct thermal_cooling_device
*cooling_dev
, unsigned long state
)
302 struct acpi_device
*device
= cooling_dev
->devdata
;
303 struct acpi_video_device
*video
= acpi_driver_data(device
);
306 if (state
>= video
->brightness
->count
- 2)
309 state
= video
->brightness
->count
- state
;
310 level
= video
->brightness
->levels
[state
- 1];
311 return acpi_video_device_lcd_set_level(video
, level
);
314 static const struct thermal_cooling_device_ops video_cooling_ops
= {
315 .get_max_state
= video_get_max_state
,
316 .get_cur_state
= video_get_cur_state
,
317 .set_cur_state
= video_set_cur_state
,
321 * --------------------------------------------------------------------------
323 * --------------------------------------------------------------------------
327 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
328 union acpi_object
**levels
)
331 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
332 union acpi_object
*obj
;
337 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
338 if (!ACPI_SUCCESS(status
))
340 obj
= (union acpi_object
*)buffer
.pointer
;
341 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
342 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
352 kfree(buffer
.pointer
);
358 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
363 status
= acpi_execute_simple_method(device
->dev
->handle
,
365 if (ACPI_FAILURE(status
)) {
366 ACPI_ERROR((AE_INFO
, "Evaluating _BCM failed"));
370 device
->brightness
->curr
= level
;
371 for (state
= 2; state
< device
->brightness
->count
; state
++)
372 if (level
== device
->brightness
->levels
[state
]) {
373 if (device
->backlight
)
374 device
->backlight
->props
.brightness
= state
- 2;
378 ACPI_ERROR((AE_INFO
, "Current brightness invalid"));
383 * For some buggy _BQC methods, we need to add a constant value to
384 * the _BQC return value to get the actual current brightness level
387 static int bqc_offset_aml_bug_workaround
;
388 static int __init
video_set_bqc_offset(const struct dmi_system_id
*d
)
390 bqc_offset_aml_bug_workaround
= 9;
394 static int video_ignore_initial_backlight(const struct dmi_system_id
*d
)
396 use_bios_initial_backlight
= 0;
400 static struct dmi_system_id video_dmi_table
[] __initdata
= {
402 * Broken _BQC workaround http://bugzilla.kernel.org/show_bug.cgi?id=13121
405 .callback
= video_set_bqc_offset
,
406 .ident
= "Acer Aspire 5720",
408 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
409 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5720"),
413 .callback
= video_set_bqc_offset
,
414 .ident
= "Acer Aspire 5710Z",
416 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
417 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5710Z"),
421 .callback
= video_set_bqc_offset
,
422 .ident
= "eMachines E510",
424 DMI_MATCH(DMI_BOARD_VENDOR
, "EMACHINES"),
425 DMI_MATCH(DMI_PRODUCT_NAME
, "eMachines E510"),
429 .callback
= video_set_bqc_offset
,
430 .ident
= "Acer Aspire 5315",
432 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
433 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 5315"),
437 .callback
= video_set_bqc_offset
,
438 .ident
= "Acer Aspire 7720",
440 DMI_MATCH(DMI_BOARD_VENDOR
, "Acer"),
441 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire 7720"),
445 .callback
= video_ignore_initial_backlight
,
446 .ident
= "HP Folio 13-2000",
448 DMI_MATCH(DMI_BOARD_VENDOR
, "Hewlett-Packard"),
449 DMI_MATCH(DMI_PRODUCT_NAME
, "HP Folio 13 - 2000 Notebook PC"),
453 .callback
= video_ignore_initial_backlight
,
454 .ident
= "Fujitsu E753",
456 DMI_MATCH(DMI_BOARD_VENDOR
, "FUJITSU"),
457 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK E753"),
461 .callback
= video_ignore_initial_backlight
,
462 .ident
= "HP Pavilion dm4",
464 DMI_MATCH(DMI_BOARD_VENDOR
, "Hewlett-Packard"),
465 DMI_MATCH(DMI_PRODUCT_NAME
, "HP Pavilion dm4 Notebook PC"),
469 .callback
= video_ignore_initial_backlight
,
470 .ident
= "HP Pavilion g6 Notebook PC",
472 DMI_MATCH(DMI_BOARD_VENDOR
, "Hewlett-Packard"),
473 DMI_MATCH(DMI_PRODUCT_NAME
, "HP Pavilion g6 Notebook PC"),
477 .callback
= video_ignore_initial_backlight
,
478 .ident
= "HP 1000 Notebook PC",
480 DMI_MATCH(DMI_BOARD_VENDOR
, "Hewlett-Packard"),
481 DMI_MATCH(DMI_PRODUCT_NAME
, "HP 1000 Notebook PC"),
485 .callback
= video_ignore_initial_backlight
,
486 .ident
= "HP Pavilion m4",
488 DMI_MATCH(DMI_BOARD_VENDOR
, "Hewlett-Packard"),
489 DMI_MATCH(DMI_PRODUCT_NAME
, "HP Pavilion m4 Notebook PC"),
495 static unsigned long long
496 acpi_video_bqc_value_to_level(struct acpi_video_device
*device
,
497 unsigned long long bqc_value
)
499 unsigned long long level
;
501 if (device
->brightness
->flags
._BQC_use_index
) {
503 * _BQC returns an index that doesn't account for
504 * the first 2 items with special meaning, so we need
505 * to compensate for that by offsetting ourselves
507 if (device
->brightness
->flags
._BCL_reversed
)
508 bqc_value
= device
->brightness
->count
- 3 - bqc_value
;
510 level
= device
->brightness
->levels
[bqc_value
+ 2];
515 level
+= bqc_offset_aml_bug_workaround
;
521 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
522 unsigned long long *level
, bool raw
)
524 acpi_status status
= AE_OK
;
527 if (device
->cap
._BQC
|| device
->cap
._BCQ
) {
528 char *buf
= device
->cap
._BQC
? "_BQC" : "_BCQ";
530 status
= acpi_evaluate_integer(device
->dev
->handle
, buf
,
532 if (ACPI_SUCCESS(status
)) {
535 * Caller has indicated he wants the raw
536 * value returned by _BQC, so don't furtherly
537 * mess with the value.
542 *level
= acpi_video_bqc_value_to_level(device
, *level
);
544 for (i
= 2; i
< device
->brightness
->count
; i
++)
545 if (device
->brightness
->levels
[i
] == *level
) {
546 device
->brightness
->curr
= *level
;
550 * BQC returned an invalid level.
553 ACPI_WARNING((AE_INFO
,
554 "%s returned an invalid level",
556 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
560 * should we return an error or ignore this failure?
561 * dev->brightness->curr is a cached value which stores
562 * the correct current backlight level in most cases.
563 * ACPI video backlight still works w/ buggy _BQC.
564 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
566 ACPI_WARNING((AE_INFO
, "Evaluating %s failed", buf
));
567 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
571 *level
= device
->brightness
->curr
;
576 acpi_video_device_EDID(struct acpi_video_device
*device
,
577 union acpi_object
**edid
, ssize_t length
)
580 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
581 union acpi_object
*obj
;
582 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
583 struct acpi_object_list args
= { 1, &arg0
};
591 arg0
.integer
.value
= 1;
592 else if (length
== 256)
593 arg0
.integer
.value
= 2;
597 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
598 if (ACPI_FAILURE(status
))
601 obj
= buffer
.pointer
;
603 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
606 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
618 * video : video bus device pointer
620 * 0. The system BIOS should NOT automatically switch(toggle)
621 * the active display output.
622 * 1. The system BIOS should automatically switch (toggle) the
623 * active display output. No switch event.
624 * 2. The _DGS value should be locked.
625 * 3. The system BIOS should not automatically switch (toggle) the
626 * active display output, but instead generate the display switch
629 * 0. The system BIOS should automatically control the brightness level
630 * of the LCD when the power changes from AC to DC
631 * 1. The system BIOS should NOT automatically control the brightness
632 * level of the LCD when the power changes from AC to DC.
638 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
642 if (!video
->cap
._DOS
)
645 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1)
647 video
->dos_setting
= (lcd_flag
<< 2) | bios_flag
;
648 status
= acpi_execute_simple_method(video
->device
->handle
, "_DOS",
649 (lcd_flag
<< 2) | bios_flag
);
650 if (ACPI_FAILURE(status
))
657 * Simple comparison function used to sort backlight levels.
661 acpi_video_cmp_level(const void *a
, const void *b
)
663 return *(int *)a
- *(int *)b
;
667 * Decides if _BQC/_BCQ for this system is usable
669 * We do this by changing the level first and then read out the current
670 * brightness level, if the value does not match, find out if it is using
671 * index. If not, clear the _BQC/_BCQ capability.
673 static int acpi_video_bqc_quirk(struct acpi_video_device
*device
,
674 int max_level
, int current_level
)
676 struct acpi_video_device_brightness
*br
= device
->brightness
;
678 unsigned long long level
;
681 /* don't mess with existing known broken systems */
682 if (bqc_offset_aml_bug_workaround
)
686 * Some systems always report current brightness level as maximum
687 * through _BQC, we need to test another value for them.
689 test_level
= current_level
== max_level
? br
->levels
[3] : max_level
;
691 result
= acpi_video_device_lcd_set_level(device
, test_level
);
695 result
= acpi_video_device_lcd_get_level_current(device
, &level
, true);
699 if (level
!= test_level
) {
700 /* buggy _BQC found, need to find out if it uses index */
701 if (level
< br
->count
) {
702 if (br
->flags
._BCL_reversed
)
703 level
= br
->count
- 3 - level
;
704 if (br
->levels
[level
+ 2] == test_level
)
705 br
->flags
._BQC_use_index
= 1;
708 if (!br
->flags
._BQC_use_index
)
709 device
->cap
._BQC
= device
->cap
._BCQ
= 0;
718 * device : video output device (LCD, CRT, ..)
721 * Maximum brightness level
723 * Allocate and initialize device->brightness.
727 acpi_video_init_brightness(struct acpi_video_device
*device
)
729 union acpi_object
*obj
= NULL
;
730 int i
, max_level
= 0, count
= 0, level_ac_battery
= 0;
731 unsigned long long level
, level_old
;
732 union acpi_object
*o
;
733 struct acpi_video_device_brightness
*br
= NULL
;
734 int result
= -EINVAL
;
736 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
737 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available "
738 "LCD brightness level\n"));
742 if (obj
->package
.count
< 2)
745 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
747 printk(KERN_ERR
"can't allocate memory\n");
752 br
->levels
= kmalloc((obj
->package
.count
+ 2) * sizeof *(br
->levels
),
759 for (i
= 0; i
< obj
->package
.count
; i
++) {
760 o
= (union acpi_object
*)&obj
->package
.elements
[i
];
761 if (o
->type
!= ACPI_TYPE_INTEGER
) {
762 printk(KERN_ERR PREFIX
"Invalid data\n");
765 br
->levels
[count
] = (u32
) o
->integer
.value
;
767 if (br
->levels
[count
] > max_level
)
768 max_level
= br
->levels
[count
];
773 * some buggy BIOS don't export the levels
774 * when machine is on AC/Battery in _BCL package.
775 * In this case, the first two elements in _BCL packages
776 * are also supported brightness levels that OS should take care of.
778 for (i
= 2; i
< count
; i
++) {
779 if (br
->levels
[i
] == br
->levels
[0])
781 if (br
->levels
[i
] == br
->levels
[1])
785 if (level_ac_battery
< 2) {
786 level_ac_battery
= 2 - level_ac_battery
;
787 br
->flags
._BCL_no_ac_battery_levels
= 1;
788 for (i
= (count
- 1 + level_ac_battery
); i
>= 2; i
--)
789 br
->levels
[i
] = br
->levels
[i
- level_ac_battery
];
790 count
+= level_ac_battery
;
791 } else if (level_ac_battery
> 2)
792 ACPI_ERROR((AE_INFO
, "Too many duplicates in _BCL package"));
794 /* Check if the _BCL package is in a reversed order */
795 if (max_level
== br
->levels
[2]) {
796 br
->flags
._BCL_reversed
= 1;
797 sort(&br
->levels
[2], count
- 2, sizeof(br
->levels
[2]),
798 acpi_video_cmp_level
, NULL
);
799 } else if (max_level
!= br
->levels
[count
- 1])
801 "Found unordered _BCL package"));
804 device
->brightness
= br
;
806 /* _BQC uses INDEX while _BCL uses VALUE in some laptops */
807 br
->curr
= level
= max_level
;
809 if (!device
->cap
._BQC
)
812 result
= acpi_video_device_lcd_get_level_current(device
,
815 goto out_free_levels
;
817 result
= acpi_video_bqc_quirk(device
, max_level
, level_old
);
819 goto out_free_levels
;
821 * cap._BQC may get cleared due to _BQC is found to be broken
822 * in acpi_video_bqc_quirk, so check again here.
824 if (!device
->cap
._BQC
)
827 if (use_bios_initial_backlight
) {
828 level
= acpi_video_bqc_value_to_level(device
, level_old
);
830 * On some buggy laptops, _BQC returns an uninitialized
831 * value when invoked for the first time, i.e.
832 * level_old is invalid (no matter whether it's a level
833 * or an index). Set the backlight to max_level in this case.
835 for (i
= 2; i
< br
->count
; i
++)
836 if (level_old
== br
->levels
[i
])
843 result
= acpi_video_device_lcd_set_level(device
, level
);
845 goto out_free_levels
;
847 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
848 "found %d brightness levels\n", count
- 2));
857 device
->brightness
= NULL
;
864 * device : video output device (LCD, CRT, ..)
869 * Find out all required AML methods defined under the output
873 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
875 if (acpi_has_method(device
->dev
->handle
, "_ADR"))
876 device
->cap
._ADR
= 1;
877 if (acpi_has_method(device
->dev
->handle
, "_BCL"))
878 device
->cap
._BCL
= 1;
879 if (acpi_has_method(device
->dev
->handle
, "_BCM"))
880 device
->cap
._BCM
= 1;
881 if (acpi_has_method(device
->dev
->handle
, "_BQC")) {
882 device
->cap
._BQC
= 1;
883 } else if (acpi_has_method(device
->dev
->handle
, "_BCQ")) {
884 printk(KERN_WARNING FW_BUG
"_BCQ is used instead of _BQC\n");
885 device
->cap
._BCQ
= 1;
888 if (acpi_has_method(device
->dev
->handle
, "_DDC"))
889 device
->cap
._DDC
= 1;
894 * device : video output device (VGA)
899 * Find out all required AML methods defined under the video bus device.
902 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
904 if (acpi_has_method(video
->device
->handle
, "_DOS"))
906 if (acpi_has_method(video
->device
->handle
, "_DOD"))
908 if (acpi_has_method(video
->device
->handle
, "_ROM"))
910 if (acpi_has_method(video
->device
->handle
, "_GPD"))
912 if (acpi_has_method(video
->device
->handle
, "_SPD"))
914 if (acpi_has_method(video
->device
->handle
, "_VPO"))
919 * Check whether the video bus device has required AML method to
920 * support the desired features
923 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
925 acpi_status status
= -ENOENT
;
931 dev
= acpi_get_pci_dev(video
->device
->handle
);
937 * Since there is no HID, CID and so on for VGA driver, we have
938 * to check well known required nodes.
941 /* Does this device support video switching? */
942 if (video
->cap
._DOS
|| video
->cap
._DOD
) {
943 if (!video
->cap
._DOS
) {
944 printk(KERN_WARNING FW_BUG
945 "ACPI(%s) defines _DOD but not _DOS\n",
946 acpi_device_bid(video
->device
));
948 video
->flags
.multihead
= 1;
952 /* Does this device support retrieving a video ROM? */
953 if (video
->cap
._ROM
) {
954 video
->flags
.rom
= 1;
958 /* Does this device support configuring which video device to POST? */
959 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
960 video
->flags
.post
= 1;
968 * --------------------------------------------------------------------------
970 * --------------------------------------------------------------------------
973 /* device interface */
974 static struct acpi_video_device_attrib
*
975 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
977 struct acpi_video_enumerated_device
*ids
;
980 for (i
= 0; i
< video
->attached_count
; i
++) {
981 ids
= &video
->attached_array
[i
];
982 if ((ids
->value
.int_val
& 0xffff) == device_id
)
983 return &ids
->value
.attrib
;
990 acpi_video_get_device_type(struct acpi_video_bus
*video
,
991 unsigned long device_id
)
993 struct acpi_video_enumerated_device
*ids
;
996 for (i
= 0; i
< video
->attached_count
; i
++) {
997 ids
= &video
->attached_array
[i
];
998 if ((ids
->value
.int_val
& 0xffff) == device_id
)
999 return ids
->value
.int_val
;
1006 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1007 struct acpi_video_bus
*video
)
1009 unsigned long long device_id
;
1010 int status
, device_type
;
1011 struct acpi_video_device
*data
;
1012 struct acpi_video_device_attrib
*attribute
;
1015 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1016 /* Some device omits _ADR, we skip them instead of fail */
1017 if (ACPI_FAILURE(status
))
1020 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1024 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1025 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1026 device
->driver_data
= data
;
1028 data
->device_id
= device_id
;
1029 data
->video
= video
;
1032 attribute
= acpi_video_get_device_attr(video
, device_id
);
1034 if (attribute
&& attribute
->device_id_scheme
) {
1035 switch (attribute
->display_type
) {
1036 case ACPI_VIDEO_DISPLAY_CRT
:
1037 data
->flags
.crt
= 1;
1039 case ACPI_VIDEO_DISPLAY_TV
:
1040 data
->flags
.tvout
= 1;
1042 case ACPI_VIDEO_DISPLAY_DVI
:
1043 data
->flags
.dvi
= 1;
1045 case ACPI_VIDEO_DISPLAY_LCD
:
1046 data
->flags
.lcd
= 1;
1049 data
->flags
.unknown
= 1;
1052 if (attribute
->bios_can_detect
)
1053 data
->flags
.bios
= 1;
1055 /* Check for legacy IDs */
1056 device_type
= acpi_video_get_device_type(video
, device_id
);
1057 /* Ignore bits 16 and 18-20 */
1058 switch (device_type
& 0xffe2ffff) {
1059 case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR
:
1060 data
->flags
.crt
= 1;
1062 case ACPI_VIDEO_DISPLAY_LEGACY_PANEL
:
1063 data
->flags
.lcd
= 1;
1065 case ACPI_VIDEO_DISPLAY_LEGACY_TV
:
1066 data
->flags
.tvout
= 1;
1069 data
->flags
.unknown
= 1;
1073 acpi_video_device_bind(video
, data
);
1074 acpi_video_device_find_cap(data
);
1076 mutex_lock(&video
->device_list_lock
);
1077 list_add_tail(&data
->entry
, &video
->video_device_list
);
1078 mutex_unlock(&video
->device_list_lock
);
1085 * video : video bus device
1090 * Enumerate the video device list of the video bus,
1091 * bind the ids with the corresponding video devices
1092 * under the video bus.
1095 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1097 struct acpi_video_device
*dev
;
1099 mutex_lock(&video
->device_list_lock
);
1101 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1102 acpi_video_device_bind(video
, dev
);
1104 mutex_unlock(&video
->device_list_lock
);
1109 * video : video bus device
1110 * device : video output device under the video
1116 * Bind the ids with the corresponding video devices
1117 * under the video bus.
1121 acpi_video_device_bind(struct acpi_video_bus
*video
,
1122 struct acpi_video_device
*device
)
1124 struct acpi_video_enumerated_device
*ids
;
1127 for (i
= 0; i
< video
->attached_count
; i
++) {
1128 ids
= &video
->attached_array
[i
];
1129 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1130 ids
->bind_info
= device
;
1131 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1138 * video : video bus device
1143 * Call _DOD to enumerate all devices attached to display adapter
1147 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1152 struct acpi_video_enumerated_device
*active_list
;
1153 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1154 union acpi_object
*dod
= NULL
;
1155 union acpi_object
*obj
;
1157 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1158 if (!ACPI_SUCCESS(status
)) {
1159 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1163 dod
= buffer
.pointer
;
1164 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1165 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1170 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1171 dod
->package
.count
));
1173 active_list
= kcalloc(1 + dod
->package
.count
,
1174 sizeof(struct acpi_video_enumerated_device
),
1182 for (i
= 0; i
< dod
->package
.count
; i
++) {
1183 obj
= &dod
->package
.elements
[i
];
1185 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1186 printk(KERN_ERR PREFIX
1187 "Invalid _DOD data in element %d\n", i
);
1191 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1192 active_list
[count
].bind_info
= NULL
;
1193 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1194 (int)obj
->integer
.value
));
1198 kfree(video
->attached_array
);
1200 video
->attached_array
= active_list
;
1201 video
->attached_count
= count
;
1204 kfree(buffer
.pointer
);
1209 acpi_video_get_next_level(struct acpi_video_device
*device
,
1210 u32 level_current
, u32 event
)
1212 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1213 max
= max_below
= 0;
1214 min
= min_above
= 255;
1215 /* Find closest level to level_current */
1216 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1217 l
= device
->brightness
->levels
[i
];
1218 if (abs(l
- level_current
) < abs(delta
)) {
1219 delta
= l
- level_current
;
1224 /* Ajust level_current to closest available level */
1225 level_current
+= delta
;
1226 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1227 l
= device
->brightness
->levels
[i
];
1232 if (l
< min_above
&& l
> level_current
)
1234 if (l
> max_below
&& l
< level_current
)
1239 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1240 return (level_current
< max
) ? min_above
: min
;
1241 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1242 return (level_current
< max
) ? min_above
: max
;
1243 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1244 return (level_current
> min
) ? max_below
: min
;
1245 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1246 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1249 return level_current
;
1254 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1256 unsigned long long level_current
, level_next
;
1257 int result
= -EINVAL
;
1259 /* no warning message if acpi_backlight=vendor is used */
1260 if (!acpi_video_backlight_support())
1263 if (!device
->brightness
)
1266 result
= acpi_video_device_lcd_get_level_current(device
,
1272 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1274 result
= acpi_video_device_lcd_set_level(device
, level_next
);
1277 backlight_force_update(device
->backlight
,
1278 BACKLIGHT_UPDATE_HOTKEY
);
1282 printk(KERN_ERR PREFIX
"Failed to switch the brightness\n");
1287 int acpi_video_get_edid(struct acpi_device
*device
, int type
, int device_id
,
1290 struct acpi_video_bus
*video
;
1291 struct acpi_video_device
*video_device
;
1292 union acpi_object
*buffer
= NULL
;
1296 if (!device
|| !acpi_driver_data(device
))
1299 video
= acpi_driver_data(device
);
1301 for (i
= 0; i
< video
->attached_count
; i
++) {
1302 video_device
= video
->attached_array
[i
].bind_info
;
1308 if (!video_device
->cap
._DDC
)
1313 case ACPI_VIDEO_DISPLAY_CRT
:
1314 if (!video_device
->flags
.crt
)
1317 case ACPI_VIDEO_DISPLAY_TV
:
1318 if (!video_device
->flags
.tvout
)
1321 case ACPI_VIDEO_DISPLAY_DVI
:
1322 if (!video_device
->flags
.dvi
)
1325 case ACPI_VIDEO_DISPLAY_LCD
:
1326 if (!video_device
->flags
.lcd
)
1330 } else if (video_device
->device_id
!= device_id
) {
1334 status
= acpi_video_device_EDID(video_device
, &buffer
, length
);
1336 if (ACPI_FAILURE(status
) || !buffer
||
1337 buffer
->type
!= ACPI_TYPE_BUFFER
) {
1339 status
= acpi_video_device_EDID(video_device
, &buffer
,
1341 if (ACPI_FAILURE(status
) || !buffer
||
1342 buffer
->type
!= ACPI_TYPE_BUFFER
) {
1347 *edid
= buffer
->buffer
.pointer
;
1353 EXPORT_SYMBOL(acpi_video_get_edid
);
1356 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1357 struct acpi_device
*device
)
1360 struct acpi_device
*dev
;
1363 * There are systems where video module known to work fine regardless
1364 * of broken _DOD and ignoring returned value here doesn't cause
1367 acpi_video_device_enumerate(video
);
1369 list_for_each_entry(dev
, &device
->children
, node
) {
1371 status
= acpi_video_bus_get_one_device(dev
, video
);
1373 dev_err(&dev
->dev
, "Can't attach device\n");
1380 /* acpi_video interface */
1383 * Win8 requires setting bit2 of _DOS to let firmware know it shouldn't
1384 * preform any automatic brightness change on receiving a notification.
1386 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1388 return acpi_video_bus_DOS(video
, 0,
1389 acpi_video_backlight_quirks() ? 1 : 0);
1392 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1394 return acpi_video_bus_DOS(video
, 0,
1395 acpi_video_backlight_quirks() ? 0 : 1);
1398 static void acpi_video_bus_notify(struct acpi_device
*device
, u32 event
)
1400 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1401 struct input_dev
*input
;
1404 if (!video
|| !video
->input
)
1407 input
= video
->input
;
1410 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1411 * most likely via hotkey. */
1412 keycode
= KEY_SWITCHVIDEOMODE
;
1415 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1417 acpi_video_device_enumerate(video
);
1418 acpi_video_device_rebind(video
);
1419 keycode
= KEY_SWITCHVIDEOMODE
;
1422 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1423 keycode
= KEY_SWITCHVIDEOMODE
;
1425 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1426 keycode
= KEY_VIDEO_NEXT
;
1428 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1429 keycode
= KEY_VIDEO_PREV
;
1433 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1434 "Unsupported event [0x%x]\n", event
));
1438 if (acpi_notifier_call_chain(device
, event
, 0))
1439 /* Something vetoed the keypress. */
1443 input_report_key(input
, keycode
, 1);
1445 input_report_key(input
, keycode
, 0);
1452 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1454 struct acpi_video_device
*video_device
= data
;
1455 struct acpi_device
*device
= NULL
;
1456 struct acpi_video_bus
*bus
;
1457 struct input_dev
*input
;
1463 device
= video_device
->dev
;
1464 bus
= video_device
->video
;
1468 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1469 if (brightness_switch_enabled
)
1470 acpi_video_switch_brightness(video_device
, event
);
1471 keycode
= KEY_BRIGHTNESS_CYCLE
;
1473 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1474 if (brightness_switch_enabled
)
1475 acpi_video_switch_brightness(video_device
, event
);
1476 keycode
= KEY_BRIGHTNESSUP
;
1478 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1479 if (brightness_switch_enabled
)
1480 acpi_video_switch_brightness(video_device
, event
);
1481 keycode
= KEY_BRIGHTNESSDOWN
;
1483 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightness */
1484 if (brightness_switch_enabled
)
1485 acpi_video_switch_brightness(video_device
, event
);
1486 keycode
= KEY_BRIGHTNESS_ZERO
;
1488 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1489 if (brightness_switch_enabled
)
1490 acpi_video_switch_brightness(video_device
, event
);
1491 keycode
= KEY_DISPLAY_OFF
;
1494 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1495 "Unsupported event [0x%x]\n", event
));
1499 acpi_notifier_call_chain(device
, event
, 0);
1502 input_report_key(input
, keycode
, 1);
1504 input_report_key(input
, keycode
, 0);
1511 static int acpi_video_resume(struct notifier_block
*nb
,
1512 unsigned long val
, void *ign
)
1514 struct acpi_video_bus
*video
;
1515 struct acpi_video_device
*video_device
;
1519 case PM_HIBERNATION_PREPARE
:
1520 case PM_SUSPEND_PREPARE
:
1521 case PM_RESTORE_PREPARE
:
1525 video
= container_of(nb
, struct acpi_video_bus
, pm_nb
);
1527 dev_info(&video
->device
->dev
, "Restoring backlight state\n");
1529 for (i
= 0; i
< video
->attached_count
; i
++) {
1530 video_device
= video
->attached_array
[i
].bind_info
;
1531 if (video_device
&& video_device
->backlight
)
1532 acpi_video_set_brightness(video_device
->backlight
);
1539 acpi_video_bus_match(acpi_handle handle
, u32 level
, void *context
,
1540 void **return_value
)
1542 struct acpi_device
*device
= context
;
1543 struct acpi_device
*sibling
;
1546 if (handle
== device
->handle
)
1547 return AE_CTRL_TERMINATE
;
1549 result
= acpi_bus_get_device(handle
, &sibling
);
1553 if (!strcmp(acpi_device_name(sibling
), ACPI_VIDEO_BUS_NAME
))
1554 return AE_ALREADY_EXISTS
;
1559 static void acpi_video_dev_register_backlight(struct acpi_video_device
*device
)
1561 if (acpi_video_backlight_support()) {
1562 struct backlight_properties props
;
1563 struct pci_dev
*pdev
;
1564 acpi_handle acpi_parent
;
1565 struct device
*parent
= NULL
;
1570 result
= acpi_video_init_brightness(device
);
1573 name
= kasprintf(GFP_KERNEL
, "acpi_video%d", count
);
1578 acpi_get_parent(device
->dev
->handle
, &acpi_parent
);
1580 pdev
= acpi_get_pci_dev(acpi_parent
);
1582 parent
= &pdev
->dev
;
1586 memset(&props
, 0, sizeof(struct backlight_properties
));
1587 props
.type
= BACKLIGHT_FIRMWARE
;
1588 props
.max_brightness
= device
->brightness
->count
- 3;
1589 device
->backlight
= backlight_device_register(name
,
1592 &acpi_backlight_ops
,
1595 if (IS_ERR(device
->backlight
))
1599 * Save current brightness level in case we have to restore it
1600 * before acpi_video_device_lcd_set_level() is called next time.
1602 device
->backlight
->props
.brightness
=
1603 acpi_video_get_brightness(device
->backlight
);
1605 device
->cooling_dev
= thermal_cooling_device_register("LCD",
1606 device
->dev
, &video_cooling_ops
);
1607 if (IS_ERR(device
->cooling_dev
)) {
1609 * Set cooling_dev to NULL so we don't crash trying to
1611 * Also, why the hell we are returning early and
1612 * not attempt to register video output if cooling
1613 * device registration failed?
1616 device
->cooling_dev
= NULL
;
1620 dev_info(&device
->dev
->dev
, "registered as cooling_device%d\n",
1621 device
->cooling_dev
->id
);
1622 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
1623 &device
->cooling_dev
->device
.kobj
,
1626 printk(KERN_ERR PREFIX
"Create sysfs link\n");
1627 result
= sysfs_create_link(&device
->cooling_dev
->device
.kobj
,
1628 &device
->dev
->dev
.kobj
, "device");
1630 printk(KERN_ERR PREFIX
"Create sysfs link\n");
1634 static int acpi_video_bus_register_backlight(struct acpi_video_bus
*video
)
1636 struct acpi_video_device
*dev
;
1638 mutex_lock(&video
->device_list_lock
);
1639 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1640 acpi_video_dev_register_backlight(dev
);
1641 mutex_unlock(&video
->device_list_lock
);
1643 video
->pm_nb
.notifier_call
= acpi_video_resume
;
1644 video
->pm_nb
.priority
= 0;
1645 return register_pm_notifier(&video
->pm_nb
);
1648 static void acpi_video_dev_unregister_backlight(struct acpi_video_device
*device
)
1650 if (device
->backlight
) {
1651 backlight_device_unregister(device
->backlight
);
1652 device
->backlight
= NULL
;
1654 if (device
->brightness
) {
1655 kfree(device
->brightness
->levels
);
1656 kfree(device
->brightness
);
1657 device
->brightness
= NULL
;
1659 if (device
->cooling_dev
) {
1660 sysfs_remove_link(&device
->dev
->dev
.kobj
, "thermal_cooling");
1661 sysfs_remove_link(&device
->cooling_dev
->device
.kobj
, "device");
1662 thermal_cooling_device_unregister(device
->cooling_dev
);
1663 device
->cooling_dev
= NULL
;
1667 static int acpi_video_bus_unregister_backlight(struct acpi_video_bus
*video
)
1669 struct acpi_video_device
*dev
;
1670 int error
= unregister_pm_notifier(&video
->pm_nb
);
1672 mutex_lock(&video
->device_list_lock
);
1673 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1674 acpi_video_dev_unregister_backlight(dev
);
1675 mutex_unlock(&video
->device_list_lock
);
1680 static void acpi_video_dev_add_notify_handler(struct acpi_video_device
*device
)
1683 struct acpi_device
*adev
= device
->dev
;
1685 status
= acpi_install_notify_handler(adev
->handle
, ACPI_DEVICE_NOTIFY
,
1686 acpi_video_device_notify
, device
);
1687 if (ACPI_FAILURE(status
))
1688 dev_err(&adev
->dev
, "Error installing notify handler\n");
1690 device
->flags
.notify
= 1;
1693 static int acpi_video_bus_add_notify_handler(struct acpi_video_bus
*video
)
1695 struct input_dev
*input
;
1696 struct acpi_video_device
*dev
;
1699 video
->input
= input
= input_allocate_device();
1705 error
= acpi_video_bus_start_devices(video
);
1707 goto err_free_input
;
1709 snprintf(video
->phys
, sizeof(video
->phys
),
1710 "%s/video/input0", acpi_device_hid(video
->device
));
1712 input
->name
= acpi_device_name(video
->device
);
1713 input
->phys
= video
->phys
;
1714 input
->id
.bustype
= BUS_HOST
;
1715 input
->id
.product
= 0x06;
1716 input
->dev
.parent
= &video
->device
->dev
;
1717 input
->evbit
[0] = BIT(EV_KEY
);
1718 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
1719 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
1720 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
1721 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
1722 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
1723 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
1724 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
1725 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
1727 error
= input_register_device(input
);
1731 mutex_lock(&video
->device_list_lock
);
1732 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1733 acpi_video_dev_add_notify_handler(dev
);
1734 mutex_unlock(&video
->device_list_lock
);
1739 acpi_video_bus_stop_devices(video
);
1741 input_free_device(input
);
1742 video
->input
= NULL
;
1747 static void acpi_video_dev_remove_notify_handler(struct acpi_video_device
*dev
)
1749 if (dev
->flags
.notify
) {
1750 acpi_remove_notify_handler(dev
->dev
->handle
, ACPI_DEVICE_NOTIFY
,
1751 acpi_video_device_notify
);
1752 dev
->flags
.notify
= 0;
1756 static void acpi_video_bus_remove_notify_handler(struct acpi_video_bus
*video
)
1758 struct acpi_video_device
*dev
;
1760 mutex_lock(&video
->device_list_lock
);
1761 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1762 acpi_video_dev_remove_notify_handler(dev
);
1763 mutex_unlock(&video
->device_list_lock
);
1765 acpi_video_bus_stop_devices(video
);
1766 input_unregister_device(video
->input
);
1767 video
->input
= NULL
;
1770 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1772 struct acpi_video_device
*dev
, *next
;
1774 mutex_lock(&video
->device_list_lock
);
1775 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1776 list_del(&dev
->entry
);
1779 mutex_unlock(&video
->device_list_lock
);
1784 static int instance
;
1786 static int acpi_video_bus_add(struct acpi_device
*device
)
1788 struct acpi_video_bus
*video
;
1792 status
= acpi_walk_namespace(ACPI_TYPE_DEVICE
,
1793 device
->parent
->handle
, 1,
1794 acpi_video_bus_match
, NULL
,
1796 if (status
== AE_ALREADY_EXISTS
) {
1797 printk(KERN_WARNING FW_BUG
1798 "Duplicate ACPI video bus devices for the"
1799 " same VGA controller, please try module "
1800 "parameter \"video.allow_duplicates=1\""
1801 "if the current driver doesn't work.\n");
1802 if (!allow_duplicates
)
1806 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1810 /* a hack to fix the duplicate name "VID" problem on T61 */
1811 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
1813 device
->pnp
.bus_id
[3] = '0' + instance
;
1816 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
1817 if (!strcmp(device
->pnp
.bus_id
, "VGA")) {
1819 device
->pnp
.bus_id
[3] = '0' + instance
;
1823 video
->device
= device
;
1824 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1825 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1826 device
->driver_data
= video
;
1828 acpi_video_bus_find_cap(video
);
1829 error
= acpi_video_bus_check(video
);
1831 goto err_free_video
;
1833 mutex_init(&video
->device_list_lock
);
1834 INIT_LIST_HEAD(&video
->video_device_list
);
1836 error
= acpi_video_bus_get_devices(video
, device
);
1840 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
1841 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
1842 video
->flags
.multihead
? "yes" : "no",
1843 video
->flags
.rom
? "yes" : "no",
1844 video
->flags
.post
? "yes" : "no");
1845 mutex_lock(&video_list_lock
);
1846 list_add_tail(&video
->entry
, &video_bus_head
);
1847 mutex_unlock(&video_list_lock
);
1849 acpi_video_bus_register_backlight(video
);
1850 acpi_video_bus_add_notify_handler(video
);
1855 acpi_video_bus_put_devices(video
);
1856 kfree(video
->attached_array
);
1859 device
->driver_data
= NULL
;
1864 static int acpi_video_bus_remove(struct acpi_device
*device
)
1866 struct acpi_video_bus
*video
= NULL
;
1869 if (!device
|| !acpi_driver_data(device
))
1872 video
= acpi_driver_data(device
);
1874 acpi_video_bus_remove_notify_handler(video
);
1875 acpi_video_bus_unregister_backlight(video
);
1876 acpi_video_bus_put_devices(video
);
1878 mutex_lock(&video_list_lock
);
1879 list_del(&video
->entry
);
1880 mutex_unlock(&video_list_lock
);
1882 kfree(video
->attached_array
);
1888 static int __init
is_i740(struct pci_dev
*dev
)
1890 if (dev
->device
== 0x00D1)
1892 if (dev
->device
== 0x7000)
1897 static int __init
intel_opregion_present(void)
1900 struct pci_dev
*dev
= NULL
;
1903 for_each_pci_dev(dev
) {
1904 if ((dev
->class >> 8) != PCI_CLASS_DISPLAY_VGA
)
1906 if (dev
->vendor
!= PCI_VENDOR_ID_INTEL
)
1908 /* We don't want to poke around undefined i740 registers */
1911 pci_read_config_dword(dev
, 0xfc, &address
);
1919 int acpi_video_register(void)
1922 if (register_count
) {
1924 * if the function of acpi_video_register is already called,
1925 * don't register the acpi_vide_bus again and return no error.
1930 mutex_init(&video_list_lock
);
1931 INIT_LIST_HEAD(&video_bus_head
);
1933 result
= acpi_bus_register_driver(&acpi_video_bus
);
1938 * When the acpi_video_bus is loaded successfully, increase
1939 * the counter reference.
1945 EXPORT_SYMBOL(acpi_video_register
);
1947 void acpi_video_unregister(void)
1949 if (!register_count
) {
1951 * If the acpi video bus is already unloaded, don't
1952 * unload it again and return directly.
1956 acpi_bus_unregister_driver(&acpi_video_bus
);
1962 EXPORT_SYMBOL(acpi_video_unregister
);
1965 * This is kind of nasty. Hardware using Intel chipsets may require
1966 * the video opregion code to be run first in order to initialise
1967 * state before any ACPI video calls are made. To handle this we defer
1968 * registration of the video class until the opregion code has run.
1971 static int __init
acpi_video_init(void)
1973 dmi_check_system(video_dmi_table
);
1975 if (intel_opregion_present())
1978 return acpi_video_register();
1981 static void __exit
acpi_video_exit(void)
1983 acpi_video_unregister();
1988 module_init(acpi_video_init
);
1989 module_exit(acpi_video_exit
);