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/proc_fs.h>
33 #include <linux/seq_file.h>
35 #include <linux/backlight.h>
36 #include <asm/uaccess.h>
38 #include <acpi/acpi_bus.h>
39 #include <acpi/acpi_drivers.h>
41 #define ACPI_VIDEO_COMPONENT 0x08000000
42 #define ACPI_VIDEO_CLASS "video"
43 #define ACPI_VIDEO_BUS_NAME "Video Bus"
44 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
45 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
46 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
47 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
48 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
49 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
51 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
52 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
53 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
54 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
55 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
57 #define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
58 #define ACPI_VIDEO_HEAD_END (~0u)
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 acpi_video_bus_add(struct acpi_device
*device
);
74 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
76 static struct acpi_driver acpi_video_bus
= {
78 .class = ACPI_VIDEO_CLASS
,
79 .ids
= ACPI_VIDEO_HID
,
81 .add
= acpi_video_bus_add
,
82 .remove
= acpi_video_bus_remove
,
86 struct acpi_video_bus_flags
{
87 u8 multihead
:1; /* can switch video heads */
88 u8 rom
:1; /* can retrieve a video rom */
89 u8 post
:1; /* can configure the head to */
93 struct acpi_video_bus_cap
{
94 u8 _DOS
:1; /*Enable/Disable output switching */
95 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
96 u8 _ROM
:1; /*Get ROM Data */
97 u8 _GPD
:1; /*Get POST Device */
98 u8 _SPD
:1; /*Set POST Device */
99 u8 _VPO
:1; /*Video POST Options */
103 struct acpi_video_device_attrib
{
104 u32 display_index
:4; /* A zero-based instance of the Display */
105 u32 display_port_attachment
:4; /*This field differentiates the display type */
106 u32 display_type
:4; /*Describe the specific type in use */
107 u32 vendor_specific
:4; /*Chipset Vendor Specific */
108 u32 bios_can_detect
:1; /*BIOS can detect the device */
109 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
111 u32 pipe_id
:3; /*For VGA multiple-head devices. */
112 u32 reserved
:10; /*Must be 0 */
113 u32 device_id_scheme
:1; /*Device ID Scheme */
116 struct acpi_video_enumerated_device
{
119 struct acpi_video_device_attrib attrib
;
121 struct acpi_video_device
*bind_info
;
124 struct acpi_video_bus
{
125 struct acpi_device
*device
;
127 struct acpi_video_enumerated_device
*attached_array
;
129 struct acpi_video_bus_cap cap
;
130 struct acpi_video_bus_flags flags
;
131 struct semaphore sem
;
132 struct list_head video_device_list
;
133 struct proc_dir_entry
*dir
;
136 struct acpi_video_device_flags
{
146 struct acpi_video_device_cap
{
147 u8 _ADR
:1; /*Return the unique ID */
148 u8 _BCL
:1; /*Query list of brightness control levels supported */
149 u8 _BCM
:1; /*Set the brightness level */
150 u8 _BQC
:1; /* Get current brightness level */
151 u8 _DDC
:1; /*Return the EDID for this device */
152 u8 _DCS
:1; /*Return status of output device */
153 u8 _DGS
:1; /*Query graphics state */
154 u8 _DSS
:1; /*Device state set */
157 struct acpi_video_device_brightness
{
163 struct acpi_video_device
{
164 unsigned long device_id
;
165 struct acpi_video_device_flags flags
;
166 struct acpi_video_device_cap cap
;
167 struct list_head entry
;
168 struct acpi_video_bus
*video
;
169 struct acpi_device
*dev
;
170 struct acpi_video_device_brightness
*brightness
;
171 struct backlight_device
*backlight
;
175 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
176 static struct file_operations acpi_video_bus_info_fops
= {
177 .open
= acpi_video_bus_info_open_fs
,
180 .release
= single_release
,
183 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
184 static struct file_operations acpi_video_bus_ROM_fops
= {
185 .open
= acpi_video_bus_ROM_open_fs
,
188 .release
= single_release
,
191 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
193 static struct file_operations acpi_video_bus_POST_info_fops
= {
194 .open
= acpi_video_bus_POST_info_open_fs
,
197 .release
= single_release
,
200 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
201 static struct file_operations acpi_video_bus_POST_fops
= {
202 .open
= acpi_video_bus_POST_open_fs
,
205 .release
= single_release
,
208 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
209 static struct file_operations acpi_video_bus_DOS_fops
= {
210 .open
= acpi_video_bus_DOS_open_fs
,
213 .release
= single_release
,
217 static int acpi_video_device_info_open_fs(struct inode
*inode
,
219 static struct file_operations acpi_video_device_info_fops
= {
220 .open
= acpi_video_device_info_open_fs
,
223 .release
= single_release
,
226 static int acpi_video_device_state_open_fs(struct inode
*inode
,
228 static struct file_operations acpi_video_device_state_fops
= {
229 .open
= acpi_video_device_state_open_fs
,
232 .release
= single_release
,
235 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
237 static struct file_operations acpi_video_device_brightness_fops
= {
238 .open
= acpi_video_device_brightness_open_fs
,
241 .release
= single_release
,
244 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
246 static struct file_operations acpi_video_device_EDID_fops
= {
247 .open
= acpi_video_device_EDID_open_fs
,
250 .release
= single_release
,
253 static char device_decode
[][30] = {
254 "motherboard VGA device",
260 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
261 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
262 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
263 struct acpi_video_device
*device
);
264 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
265 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
);
266 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
268 static int acpi_video_device_lcd_get_level_current(
269 struct acpi_video_device
*device
,
270 unsigned long *level
);
271 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
272 u32 level_current
, u32 event
);
273 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
276 /*backlight device sysfs support*/
277 static int acpi_video_get_brightness(struct backlight_device
*bd
)
279 unsigned long cur_level
;
280 struct acpi_video_device
*vd
=
281 (struct acpi_video_device
*)class_get_devdata(&bd
->class_dev
);
282 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
283 return (int) cur_level
;
286 static int acpi_video_set_brightness(struct backlight_device
*bd
)
288 int request_level
= bd
->props
.brightness
;
289 struct acpi_video_device
*vd
=
290 (struct acpi_video_device
*)class_get_devdata(&bd
->class_dev
);
291 acpi_video_device_lcd_set_level(vd
, request_level
);
295 static struct backlight_ops acpi_backlight_ops
= {
296 .get_brightness
= acpi_video_get_brightness
,
297 .update_status
= acpi_video_set_brightness
,
300 /* --------------------------------------------------------------------------
302 -------------------------------------------------------------------------- */
307 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long *state
)
311 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
317 acpi_video_device_get_state(struct acpi_video_device
*device
,
318 unsigned long *state
)
322 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
328 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
331 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
332 struct acpi_object_list args
= { 1, &arg0
};
336 arg0
.integer
.value
= state
;
337 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
343 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
344 union acpi_object
**levels
)
347 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
348 union acpi_object
*obj
;
353 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
354 if (!ACPI_SUCCESS(status
))
356 obj
= (union acpi_object
*)buffer
.pointer
;
357 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
358 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
368 kfree(buffer
.pointer
);
374 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
377 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
378 struct acpi_object_list args
= { 1, &arg0
};
381 arg0
.integer
.value
= level
;
382 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM", &args
, NULL
);
384 printk(KERN_DEBUG
"set_level status: %x\n", status
);
389 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
390 unsigned long *level
)
394 status
= acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
, level
);
400 acpi_video_device_EDID(struct acpi_video_device
*device
,
401 union acpi_object
**edid
, ssize_t length
)
404 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
405 union acpi_object
*obj
;
406 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
407 struct acpi_object_list args
= { 1, &arg0
};
415 arg0
.integer
.value
= 1;
416 else if (length
== 256)
417 arg0
.integer
.value
= 2;
421 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
422 if (ACPI_FAILURE(status
))
425 obj
= buffer
.pointer
;
427 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
430 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
441 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
445 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
446 struct acpi_object_list args
= { 1, &arg0
};
449 arg0
.integer
.value
= option
;
451 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
452 if (ACPI_SUCCESS(status
))
453 status
= tmp
? (-EINVAL
) : (AE_OK
);
459 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long *id
)
463 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
469 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
470 unsigned long *options
)
474 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
482 * video : video bus device pointer
484 * 0. The system BIOS should NOT automatically switch(toggle)
485 * the active display output.
486 * 1. The system BIOS should automatically switch (toggle) the
487 * active display output. No switch event.
488 * 2. The _DGS value should be locked.
489 * 3. The system BIOS should not automatically switch (toggle) the
490 * active display output, but instead generate the display switch
493 * 0. The system BIOS should automatically control the brightness level
494 * of the LCD when the power changes from AC to DC
495 * 1. The system BIOS should NOT automatically control the brightness
496 * level of the LCD when the power changes from AC to DC.
502 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
504 acpi_integer status
= 0;
505 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
506 struct acpi_object_list args
= { 1, &arg0
};
509 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
513 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
514 video
->dos_setting
= arg0
.integer
.value
;
515 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
523 * device : video output device (LCD, CRT, ..)
528 * Find out all required AML methods defined under the output
532 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
535 acpi_handle h_dummy1
;
538 union acpi_object
*obj
= NULL
;
539 struct acpi_video_device_brightness
*br
= NULL
;
542 memset(&device
->cap
, 0, 4);
544 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
545 device
->cap
._ADR
= 1;
547 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
548 device
->cap
._BCL
= 1;
550 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
551 device
->cap
._BCM
= 1;
553 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
554 device
->cap
._BQC
= 1;
555 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
556 device
->cap
._DDC
= 1;
558 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
559 device
->cap
._DCS
= 1;
561 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
562 device
->cap
._DGS
= 1;
564 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
565 device
->cap
._DSS
= 1;
568 status
= acpi_video_device_lcd_query_levels(device
, &obj
);
570 if (obj
&& obj
->type
== ACPI_TYPE_PACKAGE
&& obj
->package
.count
>= 2) {
572 union acpi_object
*o
;
574 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
576 printk(KERN_ERR
"can't allocate memory\n");
578 br
->levels
= kmalloc(obj
->package
.count
*
579 sizeof *(br
->levels
), GFP_KERNEL
);
583 for (i
= 0; i
< obj
->package
.count
; i
++) {
584 o
= (union acpi_object
*)&obj
->package
.
586 if (o
->type
!= ACPI_TYPE_INTEGER
) {
587 printk(KERN_ERR PREFIX
"Invalid data\n");
590 br
->levels
[count
] = (u32
) o
->integer
.value
;
591 if (br
->levels
[count
] > max_level
)
592 max_level
= br
->levels
[count
];
601 device
->brightness
= br
;
602 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
603 "found %d brightness levels\n",
611 if (device
->cap
._BCL
&& device
->cap
._BCM
&& device
->cap
._BQC
){
613 static int count
= 0;
615 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
619 sprintf(name
, "acpi_video%d", count
++);
620 acpi_video_device_lcd_get_level_current(device
, &tmp
);
621 device
->backlight
= backlight_device_register(name
,
622 NULL
, device
, &acpi_backlight_ops
);
623 device
->backlight
->props
.max_brightness
= max_level
;
624 device
->backlight
->props
.brightness
= (int)tmp
;
625 backlight_update_status(device
->backlight
);
634 * device : video output device (VGA)
639 * Find out all required AML methods defined under the video bus device.
642 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
644 acpi_handle h_dummy1
;
646 memset(&video
->cap
, 0, 4);
647 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
650 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
653 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
656 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
659 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
662 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
668 * Check whether the video bus device has required AML method to
669 * support the desired features
672 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
674 acpi_status status
= -ENOENT
;
680 /* Since there is no HID, CID and so on for VGA driver, we have
681 * to check well known required nodes.
684 /* Does this device support video switching? */
685 if (video
->cap
._DOS
) {
686 video
->flags
.multihead
= 1;
690 /* Does this device support retrieving a video ROM? */
691 if (video
->cap
._ROM
) {
692 video
->flags
.rom
= 1;
696 /* Does this device support configuring which video device to POST? */
697 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
698 video
->flags
.post
= 1;
705 /* --------------------------------------------------------------------------
707 -------------------------------------------------------------------------- */
709 static struct proc_dir_entry
*acpi_video_dir
;
713 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
715 struct acpi_video_device
*dev
= seq
->private;
721 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
722 seq_printf(seq
, "type: ");
724 seq_printf(seq
, "CRT\n");
725 else if (dev
->flags
.lcd
)
726 seq_printf(seq
, "LCD\n");
727 else if (dev
->flags
.tvout
)
728 seq_printf(seq
, "TVOUT\n");
729 else if (dev
->flags
.dvi
)
730 seq_printf(seq
, "DVI\n");
732 seq_printf(seq
, "UNKNOWN\n");
734 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
741 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
743 return single_open(file
, acpi_video_device_info_seq_show
,
747 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
750 struct acpi_video_device
*dev
= seq
->private;
757 status
= acpi_video_device_get_state(dev
, &state
);
758 seq_printf(seq
, "state: ");
759 if (ACPI_SUCCESS(status
))
760 seq_printf(seq
, "0x%02lx\n", state
);
762 seq_printf(seq
, "<not supported>\n");
764 status
= acpi_video_device_query(dev
, &state
);
765 seq_printf(seq
, "query: ");
766 if (ACPI_SUCCESS(status
))
767 seq_printf(seq
, "0x%02lx\n", state
);
769 seq_printf(seq
, "<not supported>\n");
776 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
778 return single_open(file
, acpi_video_device_state_seq_show
,
783 acpi_video_device_write_state(struct file
*file
,
784 const char __user
* buffer
,
785 size_t count
, loff_t
* data
)
788 struct seq_file
*m
= file
->private_data
;
789 struct acpi_video_device
*dev
= m
->private;
790 char str
[12] = { 0 };
794 if (!dev
|| count
+ 1 > sizeof str
)
797 if (copy_from_user(str
, buffer
, count
))
801 state
= simple_strtoul(str
, NULL
, 0);
802 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
804 status
= acpi_video_device_set_state(dev
, state
);
813 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
815 struct acpi_video_device
*dev
= seq
->private;
819 if (!dev
|| !dev
->brightness
) {
820 seq_printf(seq
, "<not supported>\n");
824 seq_printf(seq
, "levels: ");
825 for (i
= 0; i
< dev
->brightness
->count
; i
++)
826 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
827 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
833 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
835 return single_open(file
, acpi_video_device_brightness_seq_show
,
840 acpi_video_device_write_brightness(struct file
*file
,
841 const char __user
* buffer
,
842 size_t count
, loff_t
* data
)
844 struct seq_file
*m
= file
->private_data
;
845 struct acpi_video_device
*dev
= m
->private;
847 unsigned int level
= 0;
851 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
854 if (copy_from_user(str
, buffer
, count
))
858 level
= simple_strtoul(str
, NULL
, 0);
863 /* validate through the list of available levels */
864 for (i
= 0; i
< dev
->brightness
->count
; i
++)
865 if (level
== dev
->brightness
->levels
[i
]) {
867 (acpi_video_device_lcd_set_level(dev
, level
)))
868 dev
->brightness
->curr
= level
;
875 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
877 struct acpi_video_device
*dev
= seq
->private;
880 union acpi_object
*edid
= NULL
;
886 status
= acpi_video_device_EDID(dev
, &edid
, 128);
887 if (ACPI_FAILURE(status
)) {
888 status
= acpi_video_device_EDID(dev
, &edid
, 256);
891 if (ACPI_FAILURE(status
)) {
895 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
896 for (i
= 0; i
< edid
->buffer
.length
; i
++)
897 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
902 seq_printf(seq
, "<not supported>\n");
910 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
912 return single_open(file
, acpi_video_device_EDID_seq_show
,
916 static int acpi_video_device_add_fs(struct acpi_device
*device
)
918 struct proc_dir_entry
*entry
= NULL
;
919 struct acpi_video_device
*vid_dev
;
925 vid_dev
= acpi_driver_data(device
);
929 if (!acpi_device_dir(device
)) {
930 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
931 vid_dev
->video
->dir
);
932 if (!acpi_device_dir(device
))
934 acpi_device_dir(device
)->owner
= THIS_MODULE
;
938 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
942 entry
->proc_fops
= &acpi_video_device_info_fops
;
943 entry
->data
= acpi_driver_data(device
);
944 entry
->owner
= THIS_MODULE
;
949 create_proc_entry("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
950 acpi_device_dir(device
));
954 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
955 entry
->proc_fops
= &acpi_video_device_state_fops
;
956 entry
->data
= acpi_driver_data(device
);
957 entry
->owner
= THIS_MODULE
;
960 /* 'brightness' [R/W] */
962 create_proc_entry("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
963 acpi_device_dir(device
));
967 acpi_video_device_brightness_fops
.write
= acpi_video_device_write_brightness
;
968 entry
->proc_fops
= &acpi_video_device_brightness_fops
;
969 entry
->data
= acpi_driver_data(device
);
970 entry
->owner
= THIS_MODULE
;
974 entry
= create_proc_entry("EDID", S_IRUGO
, acpi_device_dir(device
));
978 entry
->proc_fops
= &acpi_video_device_EDID_fops
;
979 entry
->data
= acpi_driver_data(device
);
980 entry
->owner
= THIS_MODULE
;
986 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
988 struct acpi_video_device
*vid_dev
;
990 vid_dev
= acpi_driver_data(device
);
991 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
994 if (acpi_device_dir(device
)) {
995 remove_proc_entry("info", acpi_device_dir(device
));
996 remove_proc_entry("state", acpi_device_dir(device
));
997 remove_proc_entry("brightness", acpi_device_dir(device
));
998 remove_proc_entry("EDID", acpi_device_dir(device
));
999 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1000 acpi_device_dir(device
) = NULL
;
1007 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1009 struct acpi_video_bus
*video
= seq
->private;
1015 seq_printf(seq
, "Switching heads: %s\n",
1016 video
->flags
.multihead
? "yes" : "no");
1017 seq_printf(seq
, "Video ROM: %s\n",
1018 video
->flags
.rom
? "yes" : "no");
1019 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1020 video
->flags
.post
? "yes" : "no");
1026 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1028 return single_open(file
, acpi_video_bus_info_seq_show
,
1032 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1034 struct acpi_video_bus
*video
= seq
->private;
1040 printk(KERN_INFO PREFIX
"Please implement %s\n", __FUNCTION__
);
1041 seq_printf(seq
, "<TODO>\n");
1047 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1049 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1052 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1054 struct acpi_video_bus
*video
= seq
->private;
1055 unsigned long options
;
1062 status
= acpi_video_bus_POST_options(video
, &options
);
1063 if (ACPI_SUCCESS(status
)) {
1064 if (!(options
& 1)) {
1065 printk(KERN_WARNING PREFIX
1066 "The motherboard VGA device is not listed as a possible POST device.\n");
1067 printk(KERN_WARNING PREFIX
1068 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1070 printk("%lx\n", options
);
1071 seq_printf(seq
, "can POST: <integrated video>");
1073 seq_printf(seq
, " <PCI video>");
1075 seq_printf(seq
, " <AGP video>");
1076 seq_putc(seq
, '\n');
1078 seq_printf(seq
, "<not supported>\n");
1084 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1086 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1090 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1092 struct acpi_video_bus
*video
= seq
->private;
1100 status
= acpi_video_bus_get_POST(video
, &id
);
1101 if (!ACPI_SUCCESS(status
)) {
1102 seq_printf(seq
, "<not supported>\n");
1105 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1111 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1113 struct acpi_video_bus
*video
= seq
->private;
1116 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1121 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1123 return single_open(file
, acpi_video_bus_POST_seq_show
,
1127 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1129 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1133 acpi_video_bus_write_POST(struct file
*file
,
1134 const char __user
* buffer
,
1135 size_t count
, loff_t
* data
)
1138 struct seq_file
*m
= file
->private_data
;
1139 struct acpi_video_bus
*video
= m
->private;
1140 char str
[12] = { 0 };
1141 unsigned long opt
, options
;
1144 if (!video
|| count
+ 1 > sizeof str
)
1147 status
= acpi_video_bus_POST_options(video
, &options
);
1148 if (!ACPI_SUCCESS(status
))
1151 if (copy_from_user(str
, buffer
, count
))
1155 opt
= strtoul(str
, NULL
, 0);
1159 /* just in case an OEM 'forgot' the motherboard... */
1162 if (options
& (1ul << opt
)) {
1163 status
= acpi_video_bus_set_POST(video
, opt
);
1164 if (!ACPI_SUCCESS(status
))
1173 acpi_video_bus_write_DOS(struct file
*file
,
1174 const char __user
* buffer
,
1175 size_t count
, loff_t
* data
)
1178 struct seq_file
*m
= file
->private_data
;
1179 struct acpi_video_bus
*video
= m
->private;
1180 char str
[12] = { 0 };
1184 if (!video
|| count
+ 1 > sizeof str
)
1187 if (copy_from_user(str
, buffer
, count
))
1191 opt
= strtoul(str
, NULL
, 0);
1195 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1197 if (!ACPI_SUCCESS(status
))
1203 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1205 struct proc_dir_entry
*entry
= NULL
;
1206 struct acpi_video_bus
*video
;
1209 video
= acpi_driver_data(device
);
1211 if (!acpi_device_dir(device
)) {
1212 acpi_device_dir(device
) = proc_mkdir(acpi_device_bid(device
),
1214 if (!acpi_device_dir(device
))
1216 video
->dir
= acpi_device_dir(device
);
1217 acpi_device_dir(device
)->owner
= THIS_MODULE
;
1221 entry
= create_proc_entry("info", S_IRUGO
, acpi_device_dir(device
));
1225 entry
->proc_fops
= &acpi_video_bus_info_fops
;
1226 entry
->data
= acpi_driver_data(device
);
1227 entry
->owner
= THIS_MODULE
;
1231 entry
= create_proc_entry("ROM", S_IRUGO
, acpi_device_dir(device
));
1235 entry
->proc_fops
= &acpi_video_bus_ROM_fops
;
1236 entry
->data
= acpi_driver_data(device
);
1237 entry
->owner
= THIS_MODULE
;
1240 /* 'POST_info' [R] */
1242 create_proc_entry("POST_info", S_IRUGO
, acpi_device_dir(device
));
1246 entry
->proc_fops
= &acpi_video_bus_POST_info_fops
;
1247 entry
->data
= acpi_driver_data(device
);
1248 entry
->owner
= THIS_MODULE
;
1253 create_proc_entry("POST", S_IFREG
| S_IRUGO
| S_IRUSR
,
1254 acpi_device_dir(device
));
1258 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1259 entry
->proc_fops
= &acpi_video_bus_POST_fops
;
1260 entry
->data
= acpi_driver_data(device
);
1261 entry
->owner
= THIS_MODULE
;
1266 create_proc_entry("DOS", S_IFREG
| S_IRUGO
| S_IRUSR
,
1267 acpi_device_dir(device
));
1271 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1272 entry
->proc_fops
= &acpi_video_bus_DOS_fops
;
1273 entry
->data
= acpi_driver_data(device
);
1274 entry
->owner
= THIS_MODULE
;
1280 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1282 struct acpi_video_bus
*video
;
1285 video
= acpi_driver_data(device
);
1287 if (acpi_device_dir(device
)) {
1288 remove_proc_entry("info", acpi_device_dir(device
));
1289 remove_proc_entry("ROM", acpi_device_dir(device
));
1290 remove_proc_entry("POST_info", acpi_device_dir(device
));
1291 remove_proc_entry("POST", acpi_device_dir(device
));
1292 remove_proc_entry("DOS", acpi_device_dir(device
));
1293 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1294 acpi_device_dir(device
) = NULL
;
1300 /* --------------------------------------------------------------------------
1302 -------------------------------------------------------------------------- */
1304 /* device interface */
1305 static struct acpi_video_device_attrib
*
1306 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1310 for(count
= 0; count
< video
->attached_count
; count
++)
1311 if((video
->attached_array
[count
].value
.int_val
& 0xffff) == device_id
)
1312 return &(video
->attached_array
[count
].value
.attrib
);
1317 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1318 struct acpi_video_bus
*video
)
1320 unsigned long device_id
;
1322 struct acpi_video_device
*data
;
1323 struct acpi_video_device_attrib
* attribute
;
1325 if (!device
|| !video
)
1329 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1330 if (ACPI_SUCCESS(status
)) {
1332 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1336 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1337 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1338 acpi_driver_data(device
) = data
;
1340 data
->device_id
= device_id
;
1341 data
->video
= video
;
1344 attribute
= acpi_video_get_device_attr(video
, device_id
);
1346 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1347 switch (attribute
->display_type
) {
1348 case ACPI_VIDEO_DISPLAY_CRT
:
1349 data
->flags
.crt
= 1;
1351 case ACPI_VIDEO_DISPLAY_TV
:
1352 data
->flags
.tvout
= 1;
1354 case ACPI_VIDEO_DISPLAY_DVI
:
1355 data
->flags
.dvi
= 1;
1357 case ACPI_VIDEO_DISPLAY_LCD
:
1358 data
->flags
.lcd
= 1;
1361 data
->flags
.unknown
= 1;
1364 if(attribute
->bios_can_detect
)
1365 data
->flags
.bios
= 1;
1367 data
->flags
.unknown
= 1;
1369 acpi_video_device_bind(video
, data
);
1370 acpi_video_device_find_cap(data
);
1372 status
= acpi_install_notify_handler(device
->handle
,
1374 acpi_video_device_notify
,
1376 if (ACPI_FAILURE(status
)) {
1377 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1378 "Error installing notify handler\n"));
1379 if(data
->brightness
)
1380 kfree(data
->brightness
->levels
);
1381 kfree(data
->brightness
);
1387 list_add_tail(&data
->entry
, &video
->video_device_list
);
1390 acpi_video_device_add_fs(device
);
1400 * video : video bus device
1405 * Enumerate the video device list of the video bus,
1406 * bind the ids with the corresponding video devices
1407 * under the video bus.
1410 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1412 struct list_head
*node
, *next
;
1413 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1414 struct acpi_video_device
*dev
=
1415 container_of(node
, struct acpi_video_device
, entry
);
1416 acpi_video_device_bind(video
, dev
);
1422 * video : video bus device
1423 * device : video output device under the video
1429 * Bind the ids with the corresponding video devices
1430 * under the video bus.
1434 acpi_video_device_bind(struct acpi_video_bus
*video
,
1435 struct acpi_video_device
*device
)
1439 #define IDS_VAL(i) video->attached_array[i].value.int_val
1440 #define IDS_BIND(i) video->attached_array[i].bind_info
1442 for (i
= 0; IDS_VAL(i
) != ACPI_VIDEO_HEAD_INVALID
&&
1443 i
< video
->attached_count
; i
++) {
1444 if (device
->device_id
== (IDS_VAL(i
) & 0xffff)) {
1445 IDS_BIND(i
) = device
;
1446 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1455 * video : video bus device
1460 * Call _DOD to enumerate all devices attached to display adapter
1464 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1469 struct acpi_video_enumerated_device
*active_device_list
;
1470 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1471 union acpi_object
*dod
= NULL
;
1472 union acpi_object
*obj
;
1474 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1475 if (!ACPI_SUCCESS(status
)) {
1476 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1480 dod
= buffer
.pointer
;
1481 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1482 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1487 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1488 dod
->package
.count
));
1490 active_device_list
= kmalloc((1 +
1491 dod
->package
.count
) *
1493 acpi_video_enumerated_device
),
1496 if (!active_device_list
) {
1502 for (i
= 0; i
< dod
->package
.count
; i
++) {
1503 obj
= &dod
->package
.elements
[i
];
1505 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1506 printk(KERN_ERR PREFIX
"Invalid _DOD data\n");
1507 active_device_list
[i
].value
.int_val
=
1508 ACPI_VIDEO_HEAD_INVALID
;
1510 active_device_list
[i
].value
.int_val
= obj
->integer
.value
;
1511 active_device_list
[i
].bind_info
= NULL
;
1512 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1513 (int)obj
->integer
.value
));
1516 active_device_list
[count
].value
.int_val
= ACPI_VIDEO_HEAD_END
;
1518 kfree(video
->attached_array
);
1520 video
->attached_array
= active_device_list
;
1521 video
->attached_count
= count
;
1523 kfree(buffer
.pointer
);
1529 * video : video bus device
1530 * event : notify event
1535 * 1. Find out the current active output device.
1536 * 2. Identify the next output device to switch to.
1537 * 3. call _DSS to do actual switch.
1540 static int acpi_video_switch_output(struct acpi_video_bus
*video
, int event
)
1542 struct list_head
*node
, *next
;
1543 struct acpi_video_device
*dev
= NULL
;
1544 struct acpi_video_device
*dev_next
= NULL
;
1545 struct acpi_video_device
*dev_prev
= NULL
;
1546 unsigned long state
;
1550 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1551 dev
= container_of(node
, struct acpi_video_device
, entry
);
1552 status
= acpi_video_device_get_state(dev
, &state
);
1555 container_of(node
->next
, struct acpi_video_device
,
1558 container_of(node
->prev
, struct acpi_video_device
,
1563 dev_next
= container_of(node
->next
, struct acpi_video_device
, entry
);
1564 dev_prev
= container_of(node
->prev
, struct acpi_video_device
, entry
);
1567 case ACPI_VIDEO_NOTIFY_CYCLE
:
1568 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
:
1569 acpi_video_device_set_state(dev
, 0);
1570 acpi_video_device_set_state(dev_next
, 0x80000001);
1572 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
:
1573 acpi_video_device_set_state(dev
, 0);
1574 acpi_video_device_set_state(dev_prev
, 0x80000001);
1583 acpi_video_get_next_level(struct acpi_video_device
*device
,
1584 u32 level_current
, u32 event
)
1586 int min
, max
, min_above
, max_below
, i
, l
;
1587 max
= max_below
= 0;
1588 min
= min_above
= 255;
1589 for (i
= 0; i
< device
->brightness
->count
; i
++) {
1590 l
= device
->brightness
->levels
[i
];
1595 if (l
< min_above
&& l
> level_current
)
1597 if (l
> max_below
&& l
< level_current
)
1602 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1603 return (level_current
< max
) ? min_above
: min
;
1604 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1605 return (level_current
< max
) ? min_above
: max
;
1606 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1607 return (level_current
> min
) ? max_below
: min
;
1608 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1609 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1612 return level_current
;
1617 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1619 unsigned long level_current
, level_next
;
1620 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1621 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1622 acpi_video_device_lcd_set_level(device
, level_next
);
1626 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1627 struct acpi_device
*device
)
1630 struct list_head
*node
, *next
;
1633 acpi_video_device_enumerate(video
);
1635 list_for_each_safe(node
, next
, &device
->children
) {
1636 struct acpi_device
*dev
=
1637 list_entry(node
, struct acpi_device
, node
);
1642 status
= acpi_video_bus_get_one_device(dev
, video
);
1643 if (ACPI_FAILURE(status
)) {
1644 ACPI_EXCEPTION((AE_INFO
, status
, "Cant attach device"));
1652 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1655 struct acpi_video_bus
*video
;
1658 if (!device
|| !device
->video
)
1661 video
= device
->video
;
1664 list_del(&device
->entry
);
1666 acpi_video_device_remove_fs(device
->dev
);
1668 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1670 acpi_video_device_notify
);
1671 backlight_device_unregister(device
->backlight
);
1675 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1678 struct list_head
*node
, *next
;
1681 list_for_each_safe(node
, next
, &video
->video_device_list
) {
1682 struct acpi_video_device
*data
=
1683 list_entry(node
, struct acpi_video_device
, entry
);
1687 status
= acpi_video_bus_put_one_device(data
);
1688 if (ACPI_FAILURE(status
))
1689 printk(KERN_WARNING PREFIX
1690 "hhuuhhuu bug in acpi video driver.\n");
1692 if (data
->brightness
)
1693 kfree(data
->brightness
->levels
);
1694 kfree(data
->brightness
);
1701 /* acpi_video interface */
1703 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1705 return acpi_video_bus_DOS(video
, 1, 0);
1708 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1710 return acpi_video_bus_DOS(video
, 0, 1);
1713 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1715 struct acpi_video_bus
*video
= data
;
1716 struct acpi_device
*device
= NULL
;
1718 printk("video bus notify\n");
1723 device
= video
->device
;
1726 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1727 * most likely via hotkey. */
1728 acpi_bus_generate_event(device
, event
, 0);
1731 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1733 acpi_video_device_enumerate(video
);
1734 acpi_video_device_rebind(video
);
1735 acpi_video_switch_output(video
, event
);
1736 acpi_bus_generate_event(device
, event
, 0);
1739 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1740 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1741 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1742 acpi_video_switch_output(video
, event
);
1743 acpi_bus_generate_event(device
, event
, 0);
1747 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1748 "Unsupported event [0x%x]\n", event
));
1755 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1757 struct acpi_video_device
*video_device
= data
;
1758 struct acpi_device
*device
= NULL
;
1763 device
= video_device
->dev
;
1766 case ACPI_VIDEO_NOTIFY_SWITCH
: /* change in status (cycle output device) */
1767 case ACPI_VIDEO_NOTIFY_PROBE
: /* change in status (output device status) */
1768 acpi_bus_generate_event(device
, event
, 0);
1770 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1771 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1772 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1773 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1774 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1775 acpi_video_switch_brightness(video_device
, event
);
1776 acpi_bus_generate_event(device
, event
, 0);
1779 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1780 "Unsupported event [0x%x]\n", event
));
1786 static int acpi_video_bus_add(struct acpi_device
*device
)
1789 acpi_status status
= 0;
1790 struct acpi_video_bus
*video
= NULL
;
1796 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
1800 video
->device
= device
;
1801 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
1802 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1803 acpi_driver_data(device
) = video
;
1805 acpi_video_bus_find_cap(video
);
1806 result
= acpi_video_bus_check(video
);
1810 result
= acpi_video_bus_add_fs(device
);
1814 init_MUTEX(&video
->sem
);
1815 INIT_LIST_HEAD(&video
->video_device_list
);
1817 acpi_video_bus_get_devices(video
, device
);
1818 acpi_video_bus_start_devices(video
);
1820 status
= acpi_install_notify_handler(device
->handle
,
1822 acpi_video_bus_notify
, video
);
1823 if (ACPI_FAILURE(status
)) {
1824 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
1825 "Error installing notify handler\n"));
1826 acpi_video_bus_stop_devices(video
);
1827 acpi_video_bus_put_devices(video
);
1828 kfree(video
->attached_array
);
1829 acpi_video_bus_remove_fs(device
);
1834 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
1835 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
1836 video
->flags
.multihead
? "yes" : "no",
1837 video
->flags
.rom
? "yes" : "no",
1838 video
->flags
.post
? "yes" : "no");
1847 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
1849 acpi_status status
= 0;
1850 struct acpi_video_bus
*video
= NULL
;
1853 if (!device
|| !acpi_driver_data(device
))
1856 video
= acpi_driver_data(device
);
1858 acpi_video_bus_stop_devices(video
);
1860 status
= acpi_remove_notify_handler(video
->device
->handle
,
1862 acpi_video_bus_notify
);
1864 acpi_video_bus_put_devices(video
);
1865 acpi_video_bus_remove_fs(device
);
1867 kfree(video
->attached_array
);
1873 static int __init
acpi_video_init(void)
1879 acpi_dbg_level = 0xFFFFFFFF;
1880 acpi_dbg_layer = 0x08000000;
1883 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1884 if (!acpi_video_dir
)
1886 acpi_video_dir
->owner
= THIS_MODULE
;
1888 result
= acpi_bus_register_driver(&acpi_video_bus
);
1890 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1897 static void __exit
acpi_video_exit(void)
1900 acpi_bus_unregister_driver(&acpi_video_bus
);
1902 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
1907 module_init(acpi_video_init
);
1908 module_exit(acpi_video_exit
);