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_CLASS "video"
45 #define ACPI_VIDEO_BUS_NAME "Video Bus"
46 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
47 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
48 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
49 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
50 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
51 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
53 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
54 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
55 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
56 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
57 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
59 #define MAX_NAME_LEN 20
61 #define ACPI_VIDEO_DISPLAY_CRT 1
62 #define ACPI_VIDEO_DISPLAY_TV 2
63 #define ACPI_VIDEO_DISPLAY_DVI 3
64 #define ACPI_VIDEO_DISPLAY_LCD 4
66 #define _COMPONENT ACPI_VIDEO_COMPONENT
67 ACPI_MODULE_NAME("video");
69 MODULE_AUTHOR("Bruno Ducrot");
70 MODULE_DESCRIPTION("ACPI Video Driver");
71 MODULE_LICENSE("GPL");
73 static int brightness_switch_enabled
= 1;
74 module_param(brightness_switch_enabled
, bool, 0644);
76 static int acpi_video_bus_add(struct acpi_device
*device
);
77 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
78 static int acpi_video_resume(struct acpi_device
*device
);
80 static const struct acpi_device_id video_device_ids
[] = {
84 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
86 static struct acpi_driver acpi_video_bus
= {
88 .class = ACPI_VIDEO_CLASS
,
89 .ids
= video_device_ids
,
91 .add
= acpi_video_bus_add
,
92 .remove
= acpi_video_bus_remove
,
93 .resume
= acpi_video_resume
,
97 struct acpi_video_bus_flags
{
98 u8 multihead
:1; /* can switch video heads */
99 u8 rom
:1; /* can retrieve a video rom */
100 u8 post
:1; /* can configure the head to */
104 struct acpi_video_bus_cap
{
105 u8 _DOS
:1; /*Enable/Disable output switching */
106 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
107 u8 _ROM
:1; /*Get ROM Data */
108 u8 _GPD
:1; /*Get POST Device */
109 u8 _SPD
:1; /*Set POST Device */
110 u8 _VPO
:1; /*Video POST Options */
114 struct acpi_video_device_attrib
{
115 u32 display_index
:4; /* A zero-based instance of the Display */
116 u32 display_port_attachment
:4; /*This field differentiates the display type */
117 u32 display_type
:4; /*Describe the specific type in use */
118 u32 vendor_specific
:4; /*Chipset Vendor Specific */
119 u32 bios_can_detect
:1; /*BIOS can detect the device */
120 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
122 u32 pipe_id
:3; /*For VGA multiple-head devices. */
123 u32 reserved
:10; /*Must be 0 */
124 u32 device_id_scheme
:1; /*Device ID Scheme */
127 struct acpi_video_enumerated_device
{
130 struct acpi_video_device_attrib attrib
;
132 struct acpi_video_device
*bind_info
;
135 struct acpi_video_bus
{
136 struct acpi_device
*device
;
138 struct acpi_video_enumerated_device
*attached_array
;
140 struct acpi_video_bus_cap cap
;
141 struct acpi_video_bus_flags flags
;
142 struct list_head video_device_list
;
143 struct mutex device_list_lock
; /* protects video_device_list */
144 struct proc_dir_entry
*dir
;
145 struct input_dev
*input
;
146 char phys
[32]; /* for input device */
149 struct acpi_video_device_flags
{
159 struct acpi_video_device_cap
{
160 u8 _ADR
:1; /*Return the unique ID */
161 u8 _BCL
:1; /*Query list of brightness control levels supported */
162 u8 _BCM
:1; /*Set the brightness level */
163 u8 _BQC
:1; /* Get current brightness level */
164 u8 _DDC
:1; /*Return the EDID for this device */
165 u8 _DCS
:1; /*Return status of output device */
166 u8 _DGS
:1; /*Query graphics state */
167 u8 _DSS
:1; /*Device state set */
170 struct acpi_video_device_brightness
{
176 struct acpi_video_device
{
177 unsigned long device_id
;
178 struct acpi_video_device_flags flags
;
179 struct acpi_video_device_cap cap
;
180 struct list_head entry
;
181 struct acpi_video_bus
*video
;
182 struct acpi_device
*dev
;
183 struct acpi_video_device_brightness
*brightness
;
184 struct backlight_device
*backlight
;
185 struct thermal_cooling_device
*cdev
;
186 struct output_device
*output_dev
;
190 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
191 static struct file_operations acpi_video_bus_info_fops
= {
192 .owner
= THIS_MODULE
,
193 .open
= acpi_video_bus_info_open_fs
,
196 .release
= single_release
,
199 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
200 static struct file_operations acpi_video_bus_ROM_fops
= {
201 .owner
= THIS_MODULE
,
202 .open
= acpi_video_bus_ROM_open_fs
,
205 .release
= single_release
,
208 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
210 static struct file_operations acpi_video_bus_POST_info_fops
= {
211 .owner
= THIS_MODULE
,
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 .owner
= THIS_MODULE
,
221 .open
= acpi_video_bus_POST_open_fs
,
224 .release
= single_release
,
227 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
228 static struct file_operations acpi_video_bus_DOS_fops
= {
229 .owner
= THIS_MODULE
,
230 .open
= acpi_video_bus_DOS_open_fs
,
233 .release
= single_release
,
237 static int acpi_video_device_info_open_fs(struct inode
*inode
,
239 static struct file_operations acpi_video_device_info_fops
= {
240 .owner
= THIS_MODULE
,
241 .open
= acpi_video_device_info_open_fs
,
244 .release
= single_release
,
247 static int acpi_video_device_state_open_fs(struct inode
*inode
,
249 static struct file_operations acpi_video_device_state_fops
= {
250 .owner
= THIS_MODULE
,
251 .open
= acpi_video_device_state_open_fs
,
254 .release
= single_release
,
257 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
259 static struct file_operations acpi_video_device_brightness_fops
= {
260 .owner
= THIS_MODULE
,
261 .open
= acpi_video_device_brightness_open_fs
,
264 .release
= single_release
,
267 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
269 static struct file_operations acpi_video_device_EDID_fops
= {
270 .owner
= THIS_MODULE
,
271 .open
= acpi_video_device_EDID_open_fs
,
274 .release
= single_release
,
277 static char device_decode
[][30] = {
278 "motherboard VGA device",
284 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
285 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
286 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
287 struct acpi_video_device
*device
);
288 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
289 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
291 static int acpi_video_device_lcd_get_level_current(
292 struct acpi_video_device
*device
,
293 unsigned long long *level
);
294 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
295 u32 level_current
, u32 event
);
296 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
298 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
299 unsigned long long *state
);
300 static int acpi_video_output_get(struct output_device
*od
);
301 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
303 /*backlight device sysfs support*/
304 static int acpi_video_get_brightness(struct backlight_device
*bd
)
306 unsigned long long cur_level
;
308 struct acpi_video_device
*vd
=
309 (struct acpi_video_device
*)bl_get_data(bd
);
310 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
311 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
312 if (vd
->brightness
->levels
[i
] == cur_level
)
313 /* The first two entries are special - see page 575
314 of the ACPI spec 3.0 */
320 static int acpi_video_set_brightness(struct backlight_device
*bd
)
322 int request_level
= bd
->props
.brightness
+2;
323 struct acpi_video_device
*vd
=
324 (struct acpi_video_device
*)bl_get_data(bd
);
325 acpi_video_device_lcd_set_level(vd
,
326 vd
->brightness
->levels
[request_level
]);
330 static struct backlight_ops acpi_backlight_ops
= {
331 .get_brightness
= acpi_video_get_brightness
,
332 .update_status
= acpi_video_set_brightness
,
335 /*video output device sysfs support*/
336 static int acpi_video_output_get(struct output_device
*od
)
338 unsigned long long state
;
339 struct acpi_video_device
*vd
=
340 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
341 acpi_video_device_get_state(vd
, &state
);
345 static int acpi_video_output_set(struct output_device
*od
)
347 unsigned long state
= od
->request_state
;
348 struct acpi_video_device
*vd
=
349 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
350 return acpi_video_device_set_state(vd
, state
);
353 static struct output_properties acpi_output_properties
= {
354 .set_state
= acpi_video_output_set
,
355 .get_status
= acpi_video_output_get
,
359 /* thermal cooling device callbacks */
360 static int video_get_max_state(struct thermal_cooling_device
*cdev
, char *buf
)
362 struct acpi_device
*device
= cdev
->devdata
;
363 struct acpi_video_device
*video
= acpi_driver_data(device
);
365 return sprintf(buf
, "%d\n", video
->brightness
->count
- 3);
368 static int video_get_cur_state(struct thermal_cooling_device
*cdev
, char *buf
)
370 struct acpi_device
*device
= cdev
->devdata
;
371 struct acpi_video_device
*video
= acpi_driver_data(device
);
372 unsigned long long level
;
375 acpi_video_device_lcd_get_level_current(video
, &level
);
376 for (state
= 2; state
< video
->brightness
->count
; state
++)
377 if (level
== video
->brightness
->levels
[state
])
378 return sprintf(buf
, "%d\n",
379 video
->brightness
->count
- state
- 1);
385 video_set_cur_state(struct thermal_cooling_device
*cdev
, unsigned int state
)
387 struct acpi_device
*device
= cdev
->devdata
;
388 struct acpi_video_device
*video
= acpi_driver_data(device
);
391 if ( state
>= video
->brightness
->count
- 2)
394 state
= video
->brightness
->count
- state
;
395 level
= video
->brightness
->levels
[state
-1];
396 return acpi_video_device_lcd_set_level(video
, level
);
399 static struct thermal_cooling_device_ops video_cooling_ops
= {
400 .get_max_state
= video_get_max_state
,
401 .get_cur_state
= video_get_cur_state
,
402 .set_cur_state
= video_set_cur_state
,
405 /* --------------------------------------------------------------------------
407 -------------------------------------------------------------------------- */
412 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long long *state
)
416 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
422 acpi_video_device_get_state(struct acpi_video_device
*device
,
423 unsigned long long *state
)
427 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
433 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
436 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
437 struct acpi_object_list args
= { 1, &arg0
};
438 unsigned long long ret
;
441 arg0
.integer
.value
= state
;
442 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
448 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
449 union acpi_object
**levels
)
452 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
453 union acpi_object
*obj
;
458 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
459 if (!ACPI_SUCCESS(status
))
461 obj
= (union acpi_object
*)buffer
.pointer
;
462 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
463 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
473 kfree(buffer
.pointer
);
479 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
482 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
483 struct acpi_object_list args
= { 1, &arg0
};
486 arg0
.integer
.value
= level
;
488 if (device
->cap
._BCM
)
489 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
491 device
->brightness
->curr
= level
;
496 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
497 unsigned long long *level
)
499 if (device
->cap
._BQC
)
500 return acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
,
502 *level
= device
->brightness
->curr
;
507 acpi_video_device_EDID(struct acpi_video_device
*device
,
508 union acpi_object
**edid
, ssize_t length
)
511 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
512 union acpi_object
*obj
;
513 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
514 struct acpi_object_list args
= { 1, &arg0
};
522 arg0
.integer
.value
= 1;
523 else if (length
== 256)
524 arg0
.integer
.value
= 2;
528 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
529 if (ACPI_FAILURE(status
))
532 obj
= buffer
.pointer
;
534 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
537 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
548 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
551 unsigned long long tmp
;
552 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
553 struct acpi_object_list args
= { 1, &arg0
};
556 arg0
.integer
.value
= option
;
558 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
559 if (ACPI_SUCCESS(status
))
560 status
= tmp
? (-EINVAL
) : (AE_OK
);
566 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long long *id
)
570 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
576 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
577 unsigned long long *options
)
581 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
589 * video : video bus device pointer
591 * 0. The system BIOS should NOT automatically switch(toggle)
592 * the active display output.
593 * 1. The system BIOS should automatically switch (toggle) the
594 * active display output. No switch event.
595 * 2. The _DGS value should be locked.
596 * 3. The system BIOS should not automatically switch (toggle) the
597 * active display output, but instead generate the display switch
600 * 0. The system BIOS should automatically control the brightness level
601 * of the LCD when the power changes from AC to DC
602 * 1. The system BIOS should NOT automatically control the brightness
603 * level of the LCD when the power changes from AC to DC.
609 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
611 acpi_integer status
= 0;
612 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
613 struct acpi_object_list args
= { 1, &arg0
};
616 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
620 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
621 video
->dos_setting
= arg0
.integer
.value
;
622 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
630 * device : video output device (LCD, CRT, ..)
633 * Maximum brightness level
635 * Allocate and initialize device->brightness.
639 acpi_video_init_brightness(struct acpi_video_device
*device
)
641 union acpi_object
*obj
= NULL
;
642 int i
, max_level
= 0, count
= 0;
643 union acpi_object
*o
;
644 struct acpi_video_device_brightness
*br
= NULL
;
646 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
647 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available "
648 "LCD brightness level\n"));
652 if (obj
->package
.count
< 2)
655 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
657 printk(KERN_ERR
"can't allocate memory\n");
661 br
->levels
= kmalloc(obj
->package
.count
* sizeof *(br
->levels
),
666 for (i
= 0; i
< obj
->package
.count
; i
++) {
667 o
= (union acpi_object
*)&obj
->package
.elements
[i
];
668 if (o
->type
!= ACPI_TYPE_INTEGER
) {
669 printk(KERN_ERR PREFIX
"Invalid data\n");
672 br
->levels
[count
] = (u32
) o
->integer
.value
;
674 if (br
->levels
[count
] > max_level
)
675 max_level
= br
->levels
[count
];
680 goto out_free_levels
;
683 device
->brightness
= br
;
684 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "found %d brightness levels\n", count
));
693 device
->brightness
= NULL
;
700 * device : video output device (LCD, CRT, ..)
705 * Find out all required AML methods defined under the output
709 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
711 acpi_handle h_dummy1
;
715 memset(&device
->cap
, 0, sizeof(device
->cap
));
717 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
718 device
->cap
._ADR
= 1;
720 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
721 device
->cap
._BCL
= 1;
723 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
724 device
->cap
._BCM
= 1;
726 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
727 device
->cap
._BQC
= 1;
728 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
729 device
->cap
._DDC
= 1;
731 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
732 device
->cap
._DCS
= 1;
734 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
735 device
->cap
._DGS
= 1;
737 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
738 device
->cap
._DSS
= 1;
741 if (acpi_video_backlight_support())
742 max_level
= acpi_video_init_brightness(device
);
744 if (device
->cap
._BCL
&& device
->cap
._BCM
&& max_level
> 0) {
746 static int count
= 0;
748 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
752 sprintf(name
, "acpi_video%d", count
++);
753 device
->backlight
= backlight_device_register(name
,
754 NULL
, device
, &acpi_backlight_ops
);
755 device
->backlight
->props
.max_brightness
= device
->brightness
->count
-3;
757 * If there exists the _BQC object, the _BQC object will be
758 * called to get the current backlight brightness. Otherwise
759 * the brightness will be set to the maximum.
761 if (device
->cap
._BQC
)
762 device
->backlight
->props
.brightness
=
763 acpi_video_get_brightness(device
->backlight
);
765 device
->backlight
->props
.brightness
=
766 device
->backlight
->props
.max_brightness
;
767 backlight_update_status(device
->backlight
);
770 device
->cdev
= thermal_cooling_device_register("LCD",
771 device
->dev
, &video_cooling_ops
);
772 if (IS_ERR(device
->cdev
))
775 dev_info(&device
->dev
->dev
, "registered as cooling_device%d\n",
777 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
778 &device
->cdev
->device
.kobj
,
781 printk(KERN_ERR PREFIX
"Create sysfs link\n");
782 result
= sysfs_create_link(&device
->cdev
->device
.kobj
,
783 &device
->dev
->dev
.kobj
, "device");
785 printk(KERN_ERR PREFIX
"Create sysfs link\n");
789 if (acpi_video_display_switch_support()) {
791 if (device
->cap
._DCS
&& device
->cap
._DSS
) {
794 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
797 sprintf(name
, "acpi_video%d", count
++);
798 device
->output_dev
= video_output_register(name
,
799 NULL
, device
, &acpi_output_properties
);
807 * device : video output device (VGA)
812 * Find out all required AML methods defined under the video bus device.
815 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
817 acpi_handle h_dummy1
;
819 memset(&video
->cap
, 0, sizeof(video
->cap
));
820 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
823 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
826 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
829 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
832 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
835 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
841 * Check whether the video bus device has required AML method to
842 * support the desired features
845 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
847 acpi_status status
= -ENOENT
;
853 dev
= acpi_get_physical_pci_device(video
->device
->handle
);
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;
929 unsigned long long state
;
935 status
= acpi_video_device_get_state(dev
, &state
);
936 seq_printf(seq
, "state: ");
937 if (ACPI_SUCCESS(status
))
938 seq_printf(seq
, "0x%02llx\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%02llx\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
, *device_dir
;
1097 struct acpi_video_device
*vid_dev
;
1099 vid_dev
= acpi_driver_data(device
);
1103 device_dir
= proc_mkdir(acpi_device_bid(device
),
1104 vid_dev
->video
->dir
);
1108 device_dir
->owner
= THIS_MODULE
;
1111 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1112 &acpi_video_device_info_fops
, acpi_driver_data(device
));
1114 goto err_remove_dir
;
1117 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
1118 entry
= proc_create_data("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1120 &acpi_video_device_state_fops
,
1121 acpi_driver_data(device
));
1123 goto err_remove_info
;
1125 /* 'brightness' [R/W] */
1126 acpi_video_device_brightness_fops
.write
=
1127 acpi_video_device_write_brightness
;
1128 entry
= proc_create_data("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1130 &acpi_video_device_brightness_fops
,
1131 acpi_driver_data(device
));
1133 goto err_remove_state
;
1136 entry
= proc_create_data("EDID", S_IRUGO
, device_dir
,
1137 &acpi_video_device_EDID_fops
,
1138 acpi_driver_data(device
));
1140 goto err_remove_brightness
;
1142 acpi_device_dir(device
) = device_dir
;
1146 err_remove_brightness
:
1147 remove_proc_entry("brightness", device_dir
);
1149 remove_proc_entry("state", device_dir
);
1151 remove_proc_entry("info", device_dir
);
1153 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1157 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1159 struct acpi_video_device
*vid_dev
;
1160 struct proc_dir_entry
*device_dir
;
1162 vid_dev
= acpi_driver_data(device
);
1163 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1166 device_dir
= acpi_device_dir(device
);
1168 remove_proc_entry("info", device_dir
);
1169 remove_proc_entry("state", device_dir
);
1170 remove_proc_entry("brightness", device_dir
);
1171 remove_proc_entry("EDID", device_dir
);
1172 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1173 acpi_device_dir(device
) = NULL
;
1180 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1182 struct acpi_video_bus
*video
= seq
->private;
1188 seq_printf(seq
, "Switching heads: %s\n",
1189 video
->flags
.multihead
? "yes" : "no");
1190 seq_printf(seq
, "Video ROM: %s\n",
1191 video
->flags
.rom
? "yes" : "no");
1192 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1193 video
->flags
.post
? "yes" : "no");
1199 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1201 return single_open(file
, acpi_video_bus_info_seq_show
,
1205 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1207 struct acpi_video_bus
*video
= seq
->private;
1213 printk(KERN_INFO PREFIX
"Please implement %s\n", __func__
);
1214 seq_printf(seq
, "<TODO>\n");
1220 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1222 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1225 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1227 struct acpi_video_bus
*video
= seq
->private;
1228 unsigned long long options
;
1235 status
= acpi_video_bus_POST_options(video
, &options
);
1236 if (ACPI_SUCCESS(status
)) {
1237 if (!(options
& 1)) {
1238 printk(KERN_WARNING PREFIX
1239 "The motherboard VGA device is not listed as a possible POST device.\n");
1240 printk(KERN_WARNING PREFIX
1241 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1243 printk("%llx\n", options
);
1244 seq_printf(seq
, "can POST: <integrated video>");
1246 seq_printf(seq
, " <PCI video>");
1248 seq_printf(seq
, " <AGP video>");
1249 seq_putc(seq
, '\n');
1251 seq_printf(seq
, "<not supported>\n");
1257 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1259 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1263 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1265 struct acpi_video_bus
*video
= seq
->private;
1267 unsigned long long id
;
1273 status
= acpi_video_bus_get_POST(video
, &id
);
1274 if (!ACPI_SUCCESS(status
)) {
1275 seq_printf(seq
, "<not supported>\n");
1278 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1284 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1286 struct acpi_video_bus
*video
= seq
->private;
1289 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1294 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1296 return single_open(file
, acpi_video_bus_POST_seq_show
,
1300 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1302 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1306 acpi_video_bus_write_POST(struct file
*file
,
1307 const char __user
* buffer
,
1308 size_t count
, loff_t
* data
)
1311 struct seq_file
*m
= file
->private_data
;
1312 struct acpi_video_bus
*video
= m
->private;
1313 char str
[12] = { 0 };
1314 unsigned long long opt
, options
;
1317 if (!video
|| count
+ 1 > sizeof str
)
1320 status
= acpi_video_bus_POST_options(video
, &options
);
1321 if (!ACPI_SUCCESS(status
))
1324 if (copy_from_user(str
, buffer
, count
))
1328 opt
= strtoul(str
, NULL
, 0);
1332 /* just in case an OEM 'forgot' the motherboard... */
1335 if (options
& (1ul << opt
)) {
1336 status
= acpi_video_bus_set_POST(video
, opt
);
1337 if (!ACPI_SUCCESS(status
))
1346 acpi_video_bus_write_DOS(struct file
*file
,
1347 const char __user
* buffer
,
1348 size_t count
, loff_t
* data
)
1351 struct seq_file
*m
= file
->private_data
;
1352 struct acpi_video_bus
*video
= m
->private;
1353 char str
[12] = { 0 };
1357 if (!video
|| count
+ 1 > sizeof str
)
1360 if (copy_from_user(str
, buffer
, count
))
1364 opt
= strtoul(str
, NULL
, 0);
1368 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1370 if (!ACPI_SUCCESS(status
))
1376 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1378 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1379 struct proc_dir_entry
*device_dir
;
1380 struct proc_dir_entry
*entry
;
1382 device_dir
= proc_mkdir(acpi_device_bid(device
), acpi_video_dir
);
1386 device_dir
->owner
= THIS_MODULE
;
1389 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1390 &acpi_video_bus_info_fops
,
1391 acpi_driver_data(device
));
1393 goto err_remove_dir
;
1396 entry
= proc_create_data("ROM", S_IRUGO
, device_dir
,
1397 &acpi_video_bus_ROM_fops
,
1398 acpi_driver_data(device
));
1400 goto err_remove_info
;
1402 /* 'POST_info' [R] */
1403 entry
= proc_create_data("POST_info", S_IRUGO
, device_dir
,
1404 &acpi_video_bus_POST_info_fops
,
1405 acpi_driver_data(device
));
1407 goto err_remove_rom
;
1410 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1411 entry
= proc_create_data("POST", S_IFREG
| S_IRUGO
| S_IWUSR
,
1413 &acpi_video_bus_POST_fops
,
1414 acpi_driver_data(device
));
1416 goto err_remove_post_info
;
1419 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1420 entry
= proc_create_data("DOS", S_IFREG
| S_IRUGO
| S_IWUSR
,
1422 &acpi_video_bus_DOS_fops
,
1423 acpi_driver_data(device
));
1425 goto err_remove_post
;
1427 video
->dir
= acpi_device_dir(device
) = device_dir
;
1431 remove_proc_entry("POST", device_dir
);
1432 err_remove_post_info
:
1433 remove_proc_entry("POST_info", device_dir
);
1435 remove_proc_entry("ROM", device_dir
);
1437 remove_proc_entry("info", device_dir
);
1439 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1443 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1445 struct proc_dir_entry
*device_dir
= acpi_device_dir(device
);
1448 remove_proc_entry("info", device_dir
);
1449 remove_proc_entry("ROM", device_dir
);
1450 remove_proc_entry("POST_info", device_dir
);
1451 remove_proc_entry("POST", device_dir
);
1452 remove_proc_entry("DOS", device_dir
);
1453 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1454 acpi_device_dir(device
) = NULL
;
1460 /* --------------------------------------------------------------------------
1462 -------------------------------------------------------------------------- */
1464 /* device interface */
1465 static struct acpi_video_device_attrib
*
1466 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1468 struct acpi_video_enumerated_device
*ids
;
1471 for (i
= 0; i
< video
->attached_count
; i
++) {
1472 ids
= &video
->attached_array
[i
];
1473 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1474 return &ids
->value
.attrib
;
1481 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1482 struct acpi_video_bus
*video
)
1484 unsigned long long device_id
;
1486 struct acpi_video_device
*data
;
1487 struct acpi_video_device_attrib
* attribute
;
1489 if (!device
|| !video
)
1493 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1494 if (ACPI_SUCCESS(status
)) {
1496 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1500 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1501 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1502 device
->driver_data
= data
;
1504 data
->device_id
= device_id
;
1505 data
->video
= video
;
1508 attribute
= acpi_video_get_device_attr(video
, device_id
);
1510 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1511 switch (attribute
->display_type
) {
1512 case ACPI_VIDEO_DISPLAY_CRT
:
1513 data
->flags
.crt
= 1;
1515 case ACPI_VIDEO_DISPLAY_TV
:
1516 data
->flags
.tvout
= 1;
1518 case ACPI_VIDEO_DISPLAY_DVI
:
1519 data
->flags
.dvi
= 1;
1521 case ACPI_VIDEO_DISPLAY_LCD
:
1522 data
->flags
.lcd
= 1;
1525 data
->flags
.unknown
= 1;
1528 if(attribute
->bios_can_detect
)
1529 data
->flags
.bios
= 1;
1531 data
->flags
.unknown
= 1;
1533 acpi_video_device_bind(video
, data
);
1534 acpi_video_device_find_cap(data
);
1536 status
= acpi_install_notify_handler(device
->handle
,
1538 acpi_video_device_notify
,
1540 if (ACPI_FAILURE(status
)) {
1541 printk(KERN_ERR PREFIX
1542 "Error installing notify handler\n");
1543 if(data
->brightness
)
1544 kfree(data
->brightness
->levels
);
1545 kfree(data
->brightness
);
1550 mutex_lock(&video
->device_list_lock
);
1551 list_add_tail(&data
->entry
, &video
->video_device_list
);
1552 mutex_unlock(&video
->device_list_lock
);
1554 acpi_video_device_add_fs(device
);
1564 * video : video bus device
1569 * Enumerate the video device list of the video bus,
1570 * bind the ids with the corresponding video devices
1571 * under the video bus.
1574 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1576 struct acpi_video_device
*dev
;
1578 mutex_lock(&video
->device_list_lock
);
1580 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1581 acpi_video_device_bind(video
, dev
);
1583 mutex_unlock(&video
->device_list_lock
);
1588 * video : video bus device
1589 * device : video output device under the video
1595 * Bind the ids with the corresponding video devices
1596 * under the video bus.
1600 acpi_video_device_bind(struct acpi_video_bus
*video
,
1601 struct acpi_video_device
*device
)
1603 struct acpi_video_enumerated_device
*ids
;
1606 for (i
= 0; i
< video
->attached_count
; i
++) {
1607 ids
= &video
->attached_array
[i
];
1608 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1609 ids
->bind_info
= device
;
1610 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1617 * video : video bus device
1622 * Call _DOD to enumerate all devices attached to display adapter
1626 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1631 struct acpi_video_enumerated_device
*active_list
;
1632 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1633 union acpi_object
*dod
= NULL
;
1634 union acpi_object
*obj
;
1636 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1637 if (!ACPI_SUCCESS(status
)) {
1638 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1642 dod
= buffer
.pointer
;
1643 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1644 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1649 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1650 dod
->package
.count
));
1652 active_list
= kcalloc(1 + dod
->package
.count
,
1653 sizeof(struct acpi_video_enumerated_device
),
1661 for (i
= 0; i
< dod
->package
.count
; i
++) {
1662 obj
= &dod
->package
.elements
[i
];
1664 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1665 printk(KERN_ERR PREFIX
1666 "Invalid _DOD data in element %d\n", i
);
1670 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1671 active_list
[count
].bind_info
= NULL
;
1672 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1673 (int)obj
->integer
.value
));
1677 kfree(video
->attached_array
);
1679 video
->attached_array
= active_list
;
1680 video
->attached_count
= count
;
1683 kfree(buffer
.pointer
);
1688 acpi_video_get_next_level(struct acpi_video_device
*device
,
1689 u32 level_current
, u32 event
)
1691 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1692 max
= max_below
= 0;
1693 min
= min_above
= 255;
1694 /* Find closest level to level_current */
1695 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1696 l
= device
->brightness
->levels
[i
];
1697 if (abs(l
- level_current
) < abs(delta
)) {
1698 delta
= l
- level_current
;
1703 /* Ajust level_current to closest available level */
1704 level_current
+= delta
;
1705 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1706 l
= device
->brightness
->levels
[i
];
1711 if (l
< min_above
&& l
> level_current
)
1713 if (l
> max_below
&& l
< level_current
)
1718 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1719 return (level_current
< max
) ? min_above
: min
;
1720 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1721 return (level_current
< max
) ? min_above
: max
;
1722 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1723 return (level_current
> min
) ? max_below
: min
;
1724 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1725 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1728 return level_current
;
1733 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1735 unsigned long long level_current
, level_next
;
1736 if (!device
->brightness
)
1738 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1739 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1740 acpi_video_device_lcd_set_level(device
, level_next
);
1744 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1745 struct acpi_device
*device
)
1748 struct acpi_device
*dev
;
1750 acpi_video_device_enumerate(video
);
1752 list_for_each_entry(dev
, &device
->children
, node
) {
1754 status
= acpi_video_bus_get_one_device(dev
, video
);
1755 if (ACPI_FAILURE(status
)) {
1756 printk(KERN_WARNING PREFIX
1757 "Cant attach device");
1764 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1767 struct acpi_video_bus
*video
;
1770 if (!device
|| !device
->video
)
1773 video
= device
->video
;
1775 acpi_video_device_remove_fs(device
->dev
);
1777 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1779 acpi_video_device_notify
);
1780 backlight_device_unregister(device
->backlight
);
1782 sysfs_remove_link(&device
->dev
->dev
.kobj
,
1784 sysfs_remove_link(&device
->cdev
->device
.kobj
,
1786 thermal_cooling_device_unregister(device
->cdev
);
1787 device
->cdev
= NULL
;
1789 video_output_unregister(device
->output_dev
);
1794 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1797 struct acpi_video_device
*dev
, *next
;
1799 mutex_lock(&video
->device_list_lock
);
1801 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1803 status
= acpi_video_bus_put_one_device(dev
);
1804 if (ACPI_FAILURE(status
))
1805 printk(KERN_WARNING PREFIX
1806 "hhuuhhuu bug in acpi video driver.\n");
1808 if (dev
->brightness
) {
1809 kfree(dev
->brightness
->levels
);
1810 kfree(dev
->brightness
);
1812 list_del(&dev
->entry
);
1816 mutex_unlock(&video
->device_list_lock
);
1821 /* acpi_video interface */
1823 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1825 return acpi_video_bus_DOS(video
, 0, 0);
1828 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1830 return acpi_video_bus_DOS(video
, 0, 1);
1833 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1835 struct acpi_video_bus
*video
= data
;
1836 struct acpi_device
*device
= NULL
;
1837 struct input_dev
*input
;
1843 device
= video
->device
;
1844 input
= video
->input
;
1847 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1848 * most likely via hotkey. */
1849 acpi_bus_generate_proc_event(device
, event
, 0);
1850 keycode
= KEY_SWITCHVIDEOMODE
;
1853 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1855 acpi_video_device_enumerate(video
);
1856 acpi_video_device_rebind(video
);
1857 acpi_bus_generate_proc_event(device
, event
, 0);
1858 keycode
= KEY_SWITCHVIDEOMODE
;
1861 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1862 acpi_bus_generate_proc_event(device
, event
, 0);
1863 keycode
= KEY_SWITCHVIDEOMODE
;
1865 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1866 acpi_bus_generate_proc_event(device
, event
, 0);
1867 keycode
= KEY_VIDEO_NEXT
;
1869 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1870 acpi_bus_generate_proc_event(device
, event
, 0);
1871 keycode
= KEY_VIDEO_PREV
;
1875 keycode
= KEY_UNKNOWN
;
1876 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1877 "Unsupported event [0x%x]\n", event
));
1881 acpi_notifier_call_chain(device
, event
, 0);
1882 input_report_key(input
, keycode
, 1);
1884 input_report_key(input
, keycode
, 0);
1890 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1892 struct acpi_video_device
*video_device
= data
;
1893 struct acpi_device
*device
= NULL
;
1894 struct acpi_video_bus
*bus
;
1895 struct input_dev
*input
;
1901 device
= video_device
->dev
;
1902 bus
= video_device
->video
;
1906 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1907 if (brightness_switch_enabled
)
1908 acpi_video_switch_brightness(video_device
, event
);
1909 acpi_bus_generate_proc_event(device
, event
, 0);
1910 keycode
= KEY_BRIGHTNESS_CYCLE
;
1912 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1913 if (brightness_switch_enabled
)
1914 acpi_video_switch_brightness(video_device
, event
);
1915 acpi_bus_generate_proc_event(device
, event
, 0);
1916 keycode
= KEY_BRIGHTNESSUP
;
1918 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1919 if (brightness_switch_enabled
)
1920 acpi_video_switch_brightness(video_device
, event
);
1921 acpi_bus_generate_proc_event(device
, event
, 0);
1922 keycode
= KEY_BRIGHTNESSDOWN
;
1924 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1925 if (brightness_switch_enabled
)
1926 acpi_video_switch_brightness(video_device
, event
);
1927 acpi_bus_generate_proc_event(device
, event
, 0);
1928 keycode
= KEY_BRIGHTNESS_ZERO
;
1930 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1931 if (brightness_switch_enabled
)
1932 acpi_video_switch_brightness(video_device
, event
);
1933 acpi_bus_generate_proc_event(device
, event
, 0);
1934 keycode
= KEY_DISPLAY_OFF
;
1937 keycode
= KEY_UNKNOWN
;
1938 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1939 "Unsupported event [0x%x]\n", event
));
1943 acpi_notifier_call_chain(device
, event
, 0);
1944 input_report_key(input
, keycode
, 1);
1946 input_report_key(input
, keycode
, 0);
1952 static int instance
;
1953 static int acpi_video_resume(struct acpi_device
*device
)
1955 struct acpi_video_bus
*video
;
1956 struct acpi_video_device
*video_device
;
1959 if (!device
|| !acpi_driver_data(device
))
1962 video
= acpi_driver_data(device
);
1964 for (i
= 0; i
< video
->attached_count
; i
++) {
1965 video_device
= video
->attached_array
[i
].bind_info
;
1966 if (video_device
&& video_device
->backlight
)
1967 acpi_video_set_brightness(video_device
->backlight
);
1972 static int acpi_video_bus_add(struct acpi_device
*device
)
1975 struct acpi_video_bus
*video
;
1976 struct input_dev
*input
;
1979 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1983 /* a hack to fix the duplicate name "VID" problem on T61 */
1984 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
1986 device
->pnp
.bus_id
[3] = '0' + instance
;
1990 video
->device
= device
;
1991 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1992 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1993 device
->driver_data
= video
;
1995 acpi_video_bus_find_cap(video
);
1996 error
= acpi_video_bus_check(video
);
1998 goto err_free_video
;
2000 error
= acpi_video_bus_add_fs(device
);
2002 goto err_free_video
;
2004 mutex_init(&video
->device_list_lock
);
2005 INIT_LIST_HEAD(&video
->video_device_list
);
2007 acpi_video_bus_get_devices(video
, device
);
2008 acpi_video_bus_start_devices(video
);
2010 status
= acpi_install_notify_handler(device
->handle
,
2012 acpi_video_bus_notify
, video
);
2013 if (ACPI_FAILURE(status
)) {
2014 printk(KERN_ERR PREFIX
2015 "Error installing notify handler\n");
2017 goto err_stop_video
;
2020 video
->input
= input
= input_allocate_device();
2023 goto err_uninstall_notify
;
2026 snprintf(video
->phys
, sizeof(video
->phys
),
2027 "%s/video/input0", acpi_device_hid(video
->device
));
2029 input
->name
= acpi_device_name(video
->device
);
2030 input
->phys
= video
->phys
;
2031 input
->id
.bustype
= BUS_HOST
;
2032 input
->id
.product
= 0x06;
2033 input
->dev
.parent
= &device
->dev
;
2034 input
->evbit
[0] = BIT(EV_KEY
);
2035 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
2036 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
2037 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
2038 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
2039 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
2040 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
2041 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
2042 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
2043 set_bit(KEY_UNKNOWN
, input
->keybit
);
2045 error
= input_register_device(input
);
2047 goto err_free_input_dev
;
2049 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
2050 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
2051 video
->flags
.multihead
? "yes" : "no",
2052 video
->flags
.rom
? "yes" : "no",
2053 video
->flags
.post
? "yes" : "no");
2058 input_free_device(input
);
2059 err_uninstall_notify
:
2060 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
2061 acpi_video_bus_notify
);
2063 acpi_video_bus_stop_devices(video
);
2064 acpi_video_bus_put_devices(video
);
2065 kfree(video
->attached_array
);
2066 acpi_video_bus_remove_fs(device
);
2069 device
->driver_data
= NULL
;
2074 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2076 acpi_status status
= 0;
2077 struct acpi_video_bus
*video
= NULL
;
2080 if (!device
|| !acpi_driver_data(device
))
2083 video
= acpi_driver_data(device
);
2085 acpi_video_bus_stop_devices(video
);
2087 status
= acpi_remove_notify_handler(video
->device
->handle
,
2089 acpi_video_bus_notify
);
2091 acpi_video_bus_put_devices(video
);
2092 acpi_video_bus_remove_fs(device
);
2094 input_unregister_device(video
->input
);
2095 kfree(video
->attached_array
);
2101 static int __init
acpi_video_init(void)
2105 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2106 if (!acpi_video_dir
)
2108 acpi_video_dir
->owner
= THIS_MODULE
;
2110 result
= acpi_bus_register_driver(&acpi_video_bus
);
2112 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2119 static void __exit
acpi_video_exit(void)
2122 acpi_bus_unregister_driver(&acpi_video_bus
);
2124 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2129 module_init(acpi_video_init
);
2130 module_exit(acpi_video_exit
);