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 <linux/sort.h>
40 #include <asm/uaccess.h>
42 #include <acpi/acpi_bus.h>
43 #include <acpi/acpi_drivers.h>
45 #define ACPI_VIDEO_CLASS "video"
46 #define ACPI_VIDEO_BUS_NAME "Video Bus"
47 #define ACPI_VIDEO_DEVICE_NAME "Video Device"
48 #define ACPI_VIDEO_NOTIFY_SWITCH 0x80
49 #define ACPI_VIDEO_NOTIFY_PROBE 0x81
50 #define ACPI_VIDEO_NOTIFY_CYCLE 0x82
51 #define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
52 #define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
54 #define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
55 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
56 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
57 #define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
58 #define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
60 #define MAX_NAME_LEN 20
62 #define ACPI_VIDEO_DISPLAY_CRT 1
63 #define ACPI_VIDEO_DISPLAY_TV 2
64 #define ACPI_VIDEO_DISPLAY_DVI 3
65 #define ACPI_VIDEO_DISPLAY_LCD 4
67 #define _COMPONENT ACPI_VIDEO_COMPONENT
68 ACPI_MODULE_NAME("video");
70 MODULE_AUTHOR("Bruno Ducrot");
71 MODULE_DESCRIPTION("ACPI Video Driver");
72 MODULE_LICENSE("GPL");
74 static int brightness_switch_enabled
= 1;
75 module_param(brightness_switch_enabled
, bool, 0644);
77 static int acpi_video_bus_add(struct acpi_device
*device
);
78 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
);
79 static int acpi_video_resume(struct acpi_device
*device
);
81 static const struct acpi_device_id video_device_ids
[] = {
85 MODULE_DEVICE_TABLE(acpi
, video_device_ids
);
87 static struct acpi_driver acpi_video_bus
= {
89 .class = ACPI_VIDEO_CLASS
,
90 .ids
= video_device_ids
,
92 .add
= acpi_video_bus_add
,
93 .remove
= acpi_video_bus_remove
,
94 .resume
= acpi_video_resume
,
98 struct acpi_video_bus_flags
{
99 u8 multihead
:1; /* can switch video heads */
100 u8 rom
:1; /* can retrieve a video rom */
101 u8 post
:1; /* can configure the head to */
105 struct acpi_video_bus_cap
{
106 u8 _DOS
:1; /*Enable/Disable output switching */
107 u8 _DOD
:1; /*Enumerate all devices attached to display adapter */
108 u8 _ROM
:1; /*Get ROM Data */
109 u8 _GPD
:1; /*Get POST Device */
110 u8 _SPD
:1; /*Set POST Device */
111 u8 _VPO
:1; /*Video POST Options */
115 struct acpi_video_device_attrib
{
116 u32 display_index
:4; /* A zero-based instance of the Display */
117 u32 display_port_attachment
:4; /*This field differentiates the display type */
118 u32 display_type
:4; /*Describe the specific type in use */
119 u32 vendor_specific
:4; /*Chipset Vendor Specific */
120 u32 bios_can_detect
:1; /*BIOS can detect the device */
121 u32 depend_on_vga
:1; /*Non-VGA output device whose power is related to
123 u32 pipe_id
:3; /*For VGA multiple-head devices. */
124 u32 reserved
:10; /*Must be 0 */
125 u32 device_id_scheme
:1; /*Device ID Scheme */
128 struct acpi_video_enumerated_device
{
131 struct acpi_video_device_attrib attrib
;
133 struct acpi_video_device
*bind_info
;
136 struct acpi_video_bus
{
137 struct acpi_device
*device
;
139 struct acpi_video_enumerated_device
*attached_array
;
141 struct acpi_video_bus_cap cap
;
142 struct acpi_video_bus_flags flags
;
143 struct list_head video_device_list
;
144 struct mutex device_list_lock
; /* protects video_device_list */
145 struct proc_dir_entry
*dir
;
146 struct input_dev
*input
;
147 char phys
[32]; /* for input device */
150 struct acpi_video_device_flags
{
160 struct acpi_video_device_cap
{
161 u8 _ADR
:1; /*Return the unique ID */
162 u8 _BCL
:1; /*Query list of brightness control levels supported */
163 u8 _BCM
:1; /*Set the brightness level */
164 u8 _BQC
:1; /* Get current brightness level */
165 u8 _DDC
:1; /*Return the EDID for this device */
166 u8 _DCS
:1; /*Return status of output device */
167 u8 _DGS
:1; /*Query graphics state */
168 u8 _DSS
:1; /*Device state set */
171 struct acpi_video_device_brightness
{
177 struct acpi_video_device
{
178 unsigned long device_id
;
179 struct acpi_video_device_flags flags
;
180 struct acpi_video_device_cap cap
;
181 struct list_head entry
;
182 struct acpi_video_bus
*video
;
183 struct acpi_device
*dev
;
184 struct acpi_video_device_brightness
*brightness
;
185 struct backlight_device
*backlight
;
186 struct thermal_cooling_device
*cdev
;
187 struct output_device
*output_dev
;
191 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
);
192 static struct file_operations acpi_video_bus_info_fops
= {
193 .owner
= THIS_MODULE
,
194 .open
= acpi_video_bus_info_open_fs
,
197 .release
= single_release
,
200 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
);
201 static struct file_operations acpi_video_bus_ROM_fops
= {
202 .owner
= THIS_MODULE
,
203 .open
= acpi_video_bus_ROM_open_fs
,
206 .release
= single_release
,
209 static int acpi_video_bus_POST_info_open_fs(struct inode
*inode
,
211 static struct file_operations acpi_video_bus_POST_info_fops
= {
212 .owner
= THIS_MODULE
,
213 .open
= acpi_video_bus_POST_info_open_fs
,
216 .release
= single_release
,
219 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
);
220 static struct file_operations acpi_video_bus_POST_fops
= {
221 .owner
= THIS_MODULE
,
222 .open
= acpi_video_bus_POST_open_fs
,
225 .release
= single_release
,
228 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
229 static struct file_operations acpi_video_bus_DOS_fops
= {
230 .owner
= THIS_MODULE
,
231 .open
= acpi_video_bus_DOS_open_fs
,
234 .release
= single_release
,
238 static int acpi_video_device_info_open_fs(struct inode
*inode
,
240 static struct file_operations acpi_video_device_info_fops
= {
241 .owner
= THIS_MODULE
,
242 .open
= acpi_video_device_info_open_fs
,
245 .release
= single_release
,
248 static int acpi_video_device_state_open_fs(struct inode
*inode
,
250 static struct file_operations acpi_video_device_state_fops
= {
251 .owner
= THIS_MODULE
,
252 .open
= acpi_video_device_state_open_fs
,
255 .release
= single_release
,
258 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
260 static struct file_operations acpi_video_device_brightness_fops
= {
261 .owner
= THIS_MODULE
,
262 .open
= acpi_video_device_brightness_open_fs
,
265 .release
= single_release
,
268 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
270 static struct file_operations acpi_video_device_EDID_fops
= {
271 .owner
= THIS_MODULE
,
272 .open
= acpi_video_device_EDID_open_fs
,
275 .release
= single_release
,
278 static char device_decode
[][30] = {
279 "motherboard VGA device",
285 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
286 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
287 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
288 struct acpi_video_device
*device
);
289 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
290 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
292 static int acpi_video_device_lcd_get_level_current(
293 struct acpi_video_device
*device
,
294 unsigned long long *level
);
295 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
296 u32 level_current
, u32 event
);
297 static int acpi_video_switch_brightness(struct acpi_video_device
*device
,
299 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
300 unsigned long long *state
);
301 static int acpi_video_output_get(struct output_device
*od
);
302 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
304 /*backlight device sysfs support*/
305 static int acpi_video_get_brightness(struct backlight_device
*bd
)
307 unsigned long long cur_level
;
309 struct acpi_video_device
*vd
=
310 (struct acpi_video_device
*)bl_get_data(bd
);
312 if (acpi_video_device_lcd_get_level_current(vd
, &cur_level
))
314 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
315 if (vd
->brightness
->levels
[i
] == cur_level
)
316 /* The first two entries are special - see page 575
317 of the ACPI spec 3.0 */
323 static int acpi_video_set_brightness(struct backlight_device
*bd
)
325 int request_level
= bd
->props
.brightness
+2;
326 struct acpi_video_device
*vd
=
327 (struct acpi_video_device
*)bl_get_data(bd
);
328 acpi_video_device_lcd_set_level(vd
,
329 vd
->brightness
->levels
[request_level
]);
333 static struct backlight_ops acpi_backlight_ops
= {
334 .get_brightness
= acpi_video_get_brightness
,
335 .update_status
= acpi_video_set_brightness
,
338 /*video output device sysfs support*/
339 static int acpi_video_output_get(struct output_device
*od
)
341 unsigned long long state
;
342 struct acpi_video_device
*vd
=
343 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
344 acpi_video_device_get_state(vd
, &state
);
348 static int acpi_video_output_set(struct output_device
*od
)
350 unsigned long state
= od
->request_state
;
351 struct acpi_video_device
*vd
=
352 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
353 return acpi_video_device_set_state(vd
, state
);
356 static struct output_properties acpi_output_properties
= {
357 .set_state
= acpi_video_output_set
,
358 .get_status
= acpi_video_output_get
,
362 /* thermal cooling device callbacks */
363 static int video_get_max_state(struct thermal_cooling_device
*cdev
, char *buf
)
365 struct acpi_device
*device
= cdev
->devdata
;
366 struct acpi_video_device
*video
= acpi_driver_data(device
);
368 return sprintf(buf
, "%d\n", video
->brightness
->count
- 3);
371 static int video_get_cur_state(struct thermal_cooling_device
*cdev
, char *buf
)
373 struct acpi_device
*device
= cdev
->devdata
;
374 struct acpi_video_device
*video
= acpi_driver_data(device
);
375 unsigned long long level
;
378 if (acpi_video_device_lcd_get_level_current(video
, &level
))
380 for (state
= 2; state
< video
->brightness
->count
; state
++)
381 if (level
== video
->brightness
->levels
[state
])
382 return sprintf(buf
, "%d\n",
383 video
->brightness
->count
- state
- 1);
389 video_set_cur_state(struct thermal_cooling_device
*cdev
, unsigned int state
)
391 struct acpi_device
*device
= cdev
->devdata
;
392 struct acpi_video_device
*video
= acpi_driver_data(device
);
395 if ( state
>= video
->brightness
->count
- 2)
398 state
= video
->brightness
->count
- state
;
399 level
= video
->brightness
->levels
[state
-1];
400 return acpi_video_device_lcd_set_level(video
, level
);
403 static struct thermal_cooling_device_ops video_cooling_ops
= {
404 .get_max_state
= video_get_max_state
,
405 .get_cur_state
= video_get_cur_state
,
406 .set_cur_state
= video_set_cur_state
,
409 /* --------------------------------------------------------------------------
411 -------------------------------------------------------------------------- */
416 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long long *state
)
420 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
426 acpi_video_device_get_state(struct acpi_video_device
*device
,
427 unsigned long long *state
)
431 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
437 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
440 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
441 struct acpi_object_list args
= { 1, &arg0
};
442 unsigned long long ret
;
445 arg0
.integer
.value
= state
;
446 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
452 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
453 union acpi_object
**levels
)
456 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
457 union acpi_object
*obj
;
462 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
463 if (!ACPI_SUCCESS(status
))
465 obj
= (union acpi_object
*)buffer
.pointer
;
466 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
467 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
477 kfree(buffer
.pointer
);
483 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
486 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
487 struct acpi_object_list args
= { 1, &arg0
};
491 arg0
.integer
.value
= level
;
493 if (device
->cap
._BCM
)
494 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
496 device
->brightness
->curr
= level
;
497 for (state
= 2; state
< device
->brightness
->count
; state
++)
498 if (level
== device
->brightness
->levels
[state
])
499 device
->backlight
->props
.brightness
= state
- 2;
505 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
506 unsigned long long *level
)
508 acpi_status status
= AE_OK
;
510 if (device
->cap
._BQC
) {
511 status
= acpi_evaluate_integer(device
->dev
->handle
, "_BQC",
513 if (ACPI_SUCCESS(status
)) {
514 device
->brightness
->curr
= *level
;
518 * should we return an error or ignore this failure?
519 * dev->brightness->curr is a cached value which stores
520 * the correct current backlight level in most cases.
521 * ACPI video backlight still works w/ buggy _BQC.
522 * http://bugzilla.kernel.org/show_bug.cgi?id=12233
524 ACPI_WARNING((AE_INFO
, "Evaluating _BQC failed"));
525 device
->cap
._BQC
= 0;
529 *level
= device
->brightness
->curr
;
534 acpi_video_device_EDID(struct acpi_video_device
*device
,
535 union acpi_object
**edid
, ssize_t length
)
538 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
539 union acpi_object
*obj
;
540 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
541 struct acpi_object_list args
= { 1, &arg0
};
549 arg0
.integer
.value
= 1;
550 else if (length
== 256)
551 arg0
.integer
.value
= 2;
555 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
556 if (ACPI_FAILURE(status
))
559 obj
= buffer
.pointer
;
561 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
564 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
575 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
578 unsigned long long tmp
;
579 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
580 struct acpi_object_list args
= { 1, &arg0
};
583 arg0
.integer
.value
= option
;
585 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
586 if (ACPI_SUCCESS(status
))
587 status
= tmp
? (-EINVAL
) : (AE_OK
);
593 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long long *id
)
597 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
603 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
604 unsigned long long *options
)
608 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
616 * video : video bus device pointer
618 * 0. The system BIOS should NOT automatically switch(toggle)
619 * the active display output.
620 * 1. The system BIOS should automatically switch (toggle) the
621 * active display output. No switch event.
622 * 2. The _DGS value should be locked.
623 * 3. The system BIOS should not automatically switch (toggle) the
624 * active display output, but instead generate the display switch
627 * 0. The system BIOS should automatically control the brightness level
628 * of the LCD when the power changes from AC to DC
629 * 1. The system BIOS should NOT automatically control the brightness
630 * level of the LCD when the power changes from AC to DC.
636 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
638 acpi_integer status
= 0;
639 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
640 struct acpi_object_list args
= { 1, &arg0
};
643 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
647 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
648 video
->dos_setting
= arg0
.integer
.value
;
649 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
656 * Simple comparison function used to sort backlight levels.
660 acpi_video_cmp_level(const void *a
, const void *b
)
662 return *(int *)a
- *(int *)b
;
667 * device : video output device (LCD, CRT, ..)
670 * Maximum brightness level
672 * Allocate and initialize device->brightness.
676 acpi_video_init_brightness(struct acpi_video_device
*device
)
678 union acpi_object
*obj
= NULL
;
679 int i
, max_level
= 0, count
= 0;
680 union acpi_object
*o
;
681 struct acpi_video_device_brightness
*br
= NULL
;
683 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
684 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available "
685 "LCD brightness level\n"));
689 if (obj
->package
.count
< 2)
692 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
694 printk(KERN_ERR
"can't allocate memory\n");
698 br
->levels
= kmalloc(obj
->package
.count
* sizeof *(br
->levels
),
703 for (i
= 0; i
< obj
->package
.count
; i
++) {
704 o
= (union acpi_object
*)&obj
->package
.elements
[i
];
705 if (o
->type
!= ACPI_TYPE_INTEGER
) {
706 printk(KERN_ERR PREFIX
"Invalid data\n");
709 br
->levels
[count
] = (u32
) o
->integer
.value
;
711 if (br
->levels
[count
] > max_level
)
712 max_level
= br
->levels
[count
];
716 /* don't sort the first two brightness levels */
717 sort(&br
->levels
[2], count
- 2, sizeof(br
->levels
[2]),
718 acpi_video_cmp_level
, NULL
);
721 goto out_free_levels
;
724 device
->brightness
= br
;
725 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "found %d brightness levels\n", count
));
734 device
->brightness
= NULL
;
741 * device : video output device (LCD, CRT, ..)
746 * Find out all required AML methods defined under the output
750 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
752 acpi_handle h_dummy1
;
756 memset(&device
->cap
, 0, sizeof(device
->cap
));
758 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
759 device
->cap
._ADR
= 1;
761 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
762 device
->cap
._BCL
= 1;
764 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
765 device
->cap
._BCM
= 1;
767 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
768 device
->cap
._BQC
= 1;
769 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
770 device
->cap
._DDC
= 1;
772 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
773 device
->cap
._DCS
= 1;
775 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
776 device
->cap
._DGS
= 1;
778 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
779 device
->cap
._DSS
= 1;
782 if (acpi_video_backlight_support())
783 max_level
= acpi_video_init_brightness(device
);
785 if (device
->cap
._BCL
&& device
->cap
._BCM
&& max_level
> 0) {
787 static int count
= 0;
789 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
793 sprintf(name
, "acpi_video%d", count
++);
794 device
->backlight
= backlight_device_register(name
,
795 NULL
, device
, &acpi_backlight_ops
);
796 device
->backlight
->props
.max_brightness
= device
->brightness
->count
-3;
798 * If there exists the _BQC object, the _BQC object will be
799 * called to get the current backlight brightness. Otherwise
800 * the brightness will be set to the maximum.
802 if (device
->cap
._BQC
)
803 device
->backlight
->props
.brightness
=
804 acpi_video_get_brightness(device
->backlight
);
806 device
->backlight
->props
.brightness
=
807 device
->backlight
->props
.max_brightness
;
808 backlight_update_status(device
->backlight
);
811 device
->cdev
= thermal_cooling_device_register("LCD",
812 device
->dev
, &video_cooling_ops
);
813 if (IS_ERR(device
->cdev
))
816 dev_info(&device
->dev
->dev
, "registered as cooling_device%d\n",
818 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
819 &device
->cdev
->device
.kobj
,
822 printk(KERN_ERR PREFIX
"Create sysfs link\n");
823 result
= sysfs_create_link(&device
->cdev
->device
.kobj
,
824 &device
->dev
->dev
.kobj
, "device");
826 printk(KERN_ERR PREFIX
"Create sysfs link\n");
830 if (acpi_video_display_switch_support()) {
832 if (device
->cap
._DCS
&& device
->cap
._DSS
) {
835 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
838 sprintf(name
, "acpi_video%d", count
++);
839 device
->output_dev
= video_output_register(name
,
840 NULL
, device
, &acpi_output_properties
);
848 * device : video output device (VGA)
853 * Find out all required AML methods defined under the video bus device.
856 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
858 acpi_handle h_dummy1
;
860 memset(&video
->cap
, 0, sizeof(video
->cap
));
861 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
864 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
867 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
870 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
873 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
876 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
882 * Check whether the video bus device has required AML method to
883 * support the desired features
886 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
888 acpi_status status
= -ENOENT
;
894 dev
= acpi_get_physical_pci_device(video
->device
->handle
);
899 /* Since there is no HID, CID and so on for VGA driver, we have
900 * to check well known required nodes.
903 /* Does this device support video switching? */
904 if (video
->cap
._DOS
) {
905 video
->flags
.multihead
= 1;
909 /* Does this device support retrieving a video ROM? */
910 if (video
->cap
._ROM
) {
911 video
->flags
.rom
= 1;
915 /* Does this device support configuring which video device to POST? */
916 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
917 video
->flags
.post
= 1;
924 /* --------------------------------------------------------------------------
926 -------------------------------------------------------------------------- */
928 static struct proc_dir_entry
*acpi_video_dir
;
932 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
934 struct acpi_video_device
*dev
= seq
->private;
940 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
941 seq_printf(seq
, "type: ");
943 seq_printf(seq
, "CRT\n");
944 else if (dev
->flags
.lcd
)
945 seq_printf(seq
, "LCD\n");
946 else if (dev
->flags
.tvout
)
947 seq_printf(seq
, "TVOUT\n");
948 else if (dev
->flags
.dvi
)
949 seq_printf(seq
, "DVI\n");
951 seq_printf(seq
, "UNKNOWN\n");
953 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
960 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
962 return single_open(file
, acpi_video_device_info_seq_show
,
966 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
969 struct acpi_video_device
*dev
= seq
->private;
970 unsigned long long state
;
976 status
= acpi_video_device_get_state(dev
, &state
);
977 seq_printf(seq
, "state: ");
978 if (ACPI_SUCCESS(status
))
979 seq_printf(seq
, "0x%02llx\n", state
);
981 seq_printf(seq
, "<not supported>\n");
983 status
= acpi_video_device_query(dev
, &state
);
984 seq_printf(seq
, "query: ");
985 if (ACPI_SUCCESS(status
))
986 seq_printf(seq
, "0x%02llx\n", state
);
988 seq_printf(seq
, "<not supported>\n");
995 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
997 return single_open(file
, acpi_video_device_state_seq_show
,
1002 acpi_video_device_write_state(struct file
*file
,
1003 const char __user
* buffer
,
1004 size_t count
, loff_t
* data
)
1007 struct seq_file
*m
= file
->private_data
;
1008 struct acpi_video_device
*dev
= m
->private;
1009 char str
[12] = { 0 };
1013 if (!dev
|| count
+ 1 > sizeof str
)
1016 if (copy_from_user(str
, buffer
, count
))
1020 state
= simple_strtoul(str
, NULL
, 0);
1021 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1023 status
= acpi_video_device_set_state(dev
, state
);
1032 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
1034 struct acpi_video_device
*dev
= seq
->private;
1038 if (!dev
|| !dev
->brightness
) {
1039 seq_printf(seq
, "<not supported>\n");
1043 seq_printf(seq
, "levels: ");
1044 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1045 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
1046 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
1052 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
1054 return single_open(file
, acpi_video_device_brightness_seq_show
,
1059 acpi_video_device_write_brightness(struct file
*file
,
1060 const char __user
* buffer
,
1061 size_t count
, loff_t
* data
)
1063 struct seq_file
*m
= file
->private_data
;
1064 struct acpi_video_device
*dev
= m
->private;
1065 char str
[5] = { 0 };
1066 unsigned int level
= 0;
1070 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
1073 if (copy_from_user(str
, buffer
, count
))
1077 level
= simple_strtoul(str
, NULL
, 0);
1082 /* validate through the list of available levels */
1083 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1084 if (level
== dev
->brightness
->levels
[i
]) {
1086 (acpi_video_device_lcd_set_level(dev
, level
)))
1087 dev
->brightness
->curr
= level
;
1094 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
1096 struct acpi_video_device
*dev
= seq
->private;
1099 union acpi_object
*edid
= NULL
;
1105 status
= acpi_video_device_EDID(dev
, &edid
, 128);
1106 if (ACPI_FAILURE(status
)) {
1107 status
= acpi_video_device_EDID(dev
, &edid
, 256);
1110 if (ACPI_FAILURE(status
)) {
1114 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
1115 for (i
= 0; i
< edid
->buffer
.length
; i
++)
1116 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
1121 seq_printf(seq
, "<not supported>\n");
1129 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
1131 return single_open(file
, acpi_video_device_EDID_seq_show
,
1135 static int acpi_video_device_add_fs(struct acpi_device
*device
)
1137 struct proc_dir_entry
*entry
, *device_dir
;
1138 struct acpi_video_device
*vid_dev
;
1140 vid_dev
= acpi_driver_data(device
);
1144 device_dir
= proc_mkdir(acpi_device_bid(device
),
1145 vid_dev
->video
->dir
);
1149 device_dir
->owner
= THIS_MODULE
;
1152 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1153 &acpi_video_device_info_fops
, acpi_driver_data(device
));
1155 goto err_remove_dir
;
1158 acpi_video_device_state_fops
.write
= acpi_video_device_write_state
;
1159 entry
= proc_create_data("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1161 &acpi_video_device_state_fops
,
1162 acpi_driver_data(device
));
1164 goto err_remove_info
;
1166 /* 'brightness' [R/W] */
1167 acpi_video_device_brightness_fops
.write
=
1168 acpi_video_device_write_brightness
;
1169 entry
= proc_create_data("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1171 &acpi_video_device_brightness_fops
,
1172 acpi_driver_data(device
));
1174 goto err_remove_state
;
1177 entry
= proc_create_data("EDID", S_IRUGO
, device_dir
,
1178 &acpi_video_device_EDID_fops
,
1179 acpi_driver_data(device
));
1181 goto err_remove_brightness
;
1183 acpi_device_dir(device
) = device_dir
;
1187 err_remove_brightness
:
1188 remove_proc_entry("brightness", device_dir
);
1190 remove_proc_entry("state", device_dir
);
1192 remove_proc_entry("info", device_dir
);
1194 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1198 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1200 struct acpi_video_device
*vid_dev
;
1201 struct proc_dir_entry
*device_dir
;
1203 vid_dev
= acpi_driver_data(device
);
1204 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1207 device_dir
= acpi_device_dir(device
);
1209 remove_proc_entry("info", device_dir
);
1210 remove_proc_entry("state", device_dir
);
1211 remove_proc_entry("brightness", device_dir
);
1212 remove_proc_entry("EDID", device_dir
);
1213 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1214 acpi_device_dir(device
) = NULL
;
1221 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1223 struct acpi_video_bus
*video
= seq
->private;
1229 seq_printf(seq
, "Switching heads: %s\n",
1230 video
->flags
.multihead
? "yes" : "no");
1231 seq_printf(seq
, "Video ROM: %s\n",
1232 video
->flags
.rom
? "yes" : "no");
1233 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1234 video
->flags
.post
? "yes" : "no");
1240 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1242 return single_open(file
, acpi_video_bus_info_seq_show
,
1246 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1248 struct acpi_video_bus
*video
= seq
->private;
1254 printk(KERN_INFO PREFIX
"Please implement %s\n", __func__
);
1255 seq_printf(seq
, "<TODO>\n");
1261 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1263 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1266 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1268 struct acpi_video_bus
*video
= seq
->private;
1269 unsigned long long options
;
1276 status
= acpi_video_bus_POST_options(video
, &options
);
1277 if (ACPI_SUCCESS(status
)) {
1278 if (!(options
& 1)) {
1279 printk(KERN_WARNING PREFIX
1280 "The motherboard VGA device is not listed as a possible POST device.\n");
1281 printk(KERN_WARNING PREFIX
1282 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1284 printk(KERN_WARNING
"%llx\n", options
);
1285 seq_printf(seq
, "can POST: <integrated video>");
1287 seq_printf(seq
, " <PCI video>");
1289 seq_printf(seq
, " <AGP video>");
1290 seq_putc(seq
, '\n');
1292 seq_printf(seq
, "<not supported>\n");
1298 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1300 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1304 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1306 struct acpi_video_bus
*video
= seq
->private;
1308 unsigned long long id
;
1314 status
= acpi_video_bus_get_POST(video
, &id
);
1315 if (!ACPI_SUCCESS(status
)) {
1316 seq_printf(seq
, "<not supported>\n");
1319 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1325 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1327 struct acpi_video_bus
*video
= seq
->private;
1330 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1335 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1337 return single_open(file
, acpi_video_bus_POST_seq_show
,
1341 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1343 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1347 acpi_video_bus_write_POST(struct file
*file
,
1348 const char __user
* buffer
,
1349 size_t count
, loff_t
* data
)
1352 struct seq_file
*m
= file
->private_data
;
1353 struct acpi_video_bus
*video
= m
->private;
1354 char str
[12] = { 0 };
1355 unsigned long long opt
, options
;
1358 if (!video
|| count
+ 1 > sizeof str
)
1361 status
= acpi_video_bus_POST_options(video
, &options
);
1362 if (!ACPI_SUCCESS(status
))
1365 if (copy_from_user(str
, buffer
, count
))
1369 opt
= strtoul(str
, NULL
, 0);
1373 /* just in case an OEM 'forgot' the motherboard... */
1376 if (options
& (1ul << opt
)) {
1377 status
= acpi_video_bus_set_POST(video
, opt
);
1378 if (!ACPI_SUCCESS(status
))
1387 acpi_video_bus_write_DOS(struct file
*file
,
1388 const char __user
* buffer
,
1389 size_t count
, loff_t
* data
)
1392 struct seq_file
*m
= file
->private_data
;
1393 struct acpi_video_bus
*video
= m
->private;
1394 char str
[12] = { 0 };
1398 if (!video
|| count
+ 1 > sizeof str
)
1401 if (copy_from_user(str
, buffer
, count
))
1405 opt
= strtoul(str
, NULL
, 0);
1409 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1411 if (!ACPI_SUCCESS(status
))
1417 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1419 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1420 struct proc_dir_entry
*device_dir
;
1421 struct proc_dir_entry
*entry
;
1423 device_dir
= proc_mkdir(acpi_device_bid(device
), acpi_video_dir
);
1427 device_dir
->owner
= THIS_MODULE
;
1430 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1431 &acpi_video_bus_info_fops
,
1432 acpi_driver_data(device
));
1434 goto err_remove_dir
;
1437 entry
= proc_create_data("ROM", S_IRUGO
, device_dir
,
1438 &acpi_video_bus_ROM_fops
,
1439 acpi_driver_data(device
));
1441 goto err_remove_info
;
1443 /* 'POST_info' [R] */
1444 entry
= proc_create_data("POST_info", S_IRUGO
, device_dir
,
1445 &acpi_video_bus_POST_info_fops
,
1446 acpi_driver_data(device
));
1448 goto err_remove_rom
;
1451 acpi_video_bus_POST_fops
.write
= acpi_video_bus_write_POST
;
1452 entry
= proc_create_data("POST", S_IFREG
| S_IRUGO
| S_IWUSR
,
1454 &acpi_video_bus_POST_fops
,
1455 acpi_driver_data(device
));
1457 goto err_remove_post_info
;
1460 acpi_video_bus_DOS_fops
.write
= acpi_video_bus_write_DOS
;
1461 entry
= proc_create_data("DOS", S_IFREG
| S_IRUGO
| S_IWUSR
,
1463 &acpi_video_bus_DOS_fops
,
1464 acpi_driver_data(device
));
1466 goto err_remove_post
;
1468 video
->dir
= acpi_device_dir(device
) = device_dir
;
1472 remove_proc_entry("POST", device_dir
);
1473 err_remove_post_info
:
1474 remove_proc_entry("POST_info", device_dir
);
1476 remove_proc_entry("ROM", device_dir
);
1478 remove_proc_entry("info", device_dir
);
1480 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1484 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1486 struct proc_dir_entry
*device_dir
= acpi_device_dir(device
);
1489 remove_proc_entry("info", device_dir
);
1490 remove_proc_entry("ROM", device_dir
);
1491 remove_proc_entry("POST_info", device_dir
);
1492 remove_proc_entry("POST", device_dir
);
1493 remove_proc_entry("DOS", device_dir
);
1494 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1495 acpi_device_dir(device
) = NULL
;
1501 /* --------------------------------------------------------------------------
1503 -------------------------------------------------------------------------- */
1505 /* device interface */
1506 static struct acpi_video_device_attrib
*
1507 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1509 struct acpi_video_enumerated_device
*ids
;
1512 for (i
= 0; i
< video
->attached_count
; i
++) {
1513 ids
= &video
->attached_array
[i
];
1514 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1515 return &ids
->value
.attrib
;
1522 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1523 struct acpi_video_bus
*video
)
1525 unsigned long long device_id
;
1527 struct acpi_video_device
*data
;
1528 struct acpi_video_device_attrib
* attribute
;
1530 if (!device
|| !video
)
1534 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1535 if (ACPI_SUCCESS(status
)) {
1537 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1541 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1542 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1543 device
->driver_data
= data
;
1545 data
->device_id
= device_id
;
1546 data
->video
= video
;
1549 attribute
= acpi_video_get_device_attr(video
, device_id
);
1551 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1552 switch (attribute
->display_type
) {
1553 case ACPI_VIDEO_DISPLAY_CRT
:
1554 data
->flags
.crt
= 1;
1556 case ACPI_VIDEO_DISPLAY_TV
:
1557 data
->flags
.tvout
= 1;
1559 case ACPI_VIDEO_DISPLAY_DVI
:
1560 data
->flags
.dvi
= 1;
1562 case ACPI_VIDEO_DISPLAY_LCD
:
1563 data
->flags
.lcd
= 1;
1566 data
->flags
.unknown
= 1;
1569 if(attribute
->bios_can_detect
)
1570 data
->flags
.bios
= 1;
1572 data
->flags
.unknown
= 1;
1574 acpi_video_device_bind(video
, data
);
1575 acpi_video_device_find_cap(data
);
1577 status
= acpi_install_notify_handler(device
->handle
,
1579 acpi_video_device_notify
,
1581 if (ACPI_FAILURE(status
)) {
1582 printk(KERN_ERR PREFIX
1583 "Error installing notify handler\n");
1584 if(data
->brightness
)
1585 kfree(data
->brightness
->levels
);
1586 kfree(data
->brightness
);
1591 mutex_lock(&video
->device_list_lock
);
1592 list_add_tail(&data
->entry
, &video
->video_device_list
);
1593 mutex_unlock(&video
->device_list_lock
);
1595 acpi_video_device_add_fs(device
);
1605 * video : video bus device
1610 * Enumerate the video device list of the video bus,
1611 * bind the ids with the corresponding video devices
1612 * under the video bus.
1615 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1617 struct acpi_video_device
*dev
;
1619 mutex_lock(&video
->device_list_lock
);
1621 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1622 acpi_video_device_bind(video
, dev
);
1624 mutex_unlock(&video
->device_list_lock
);
1629 * video : video bus device
1630 * device : video output device under the video
1636 * Bind the ids with the corresponding video devices
1637 * under the video bus.
1641 acpi_video_device_bind(struct acpi_video_bus
*video
,
1642 struct acpi_video_device
*device
)
1644 struct acpi_video_enumerated_device
*ids
;
1647 for (i
= 0; i
< video
->attached_count
; i
++) {
1648 ids
= &video
->attached_array
[i
];
1649 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1650 ids
->bind_info
= device
;
1651 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1658 * video : video bus device
1663 * Call _DOD to enumerate all devices attached to display adapter
1667 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1672 struct acpi_video_enumerated_device
*active_list
;
1673 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1674 union acpi_object
*dod
= NULL
;
1675 union acpi_object
*obj
;
1677 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1678 if (!ACPI_SUCCESS(status
)) {
1679 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1683 dod
= buffer
.pointer
;
1684 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1685 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1690 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1691 dod
->package
.count
));
1693 active_list
= kcalloc(1 + dod
->package
.count
,
1694 sizeof(struct acpi_video_enumerated_device
),
1702 for (i
= 0; i
< dod
->package
.count
; i
++) {
1703 obj
= &dod
->package
.elements
[i
];
1705 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1706 printk(KERN_ERR PREFIX
1707 "Invalid _DOD data in element %d\n", i
);
1711 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1712 active_list
[count
].bind_info
= NULL
;
1713 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1714 (int)obj
->integer
.value
));
1718 kfree(video
->attached_array
);
1720 video
->attached_array
= active_list
;
1721 video
->attached_count
= count
;
1724 kfree(buffer
.pointer
);
1729 acpi_video_get_next_level(struct acpi_video_device
*device
,
1730 u32 level_current
, u32 event
)
1732 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1733 max
= max_below
= 0;
1734 min
= min_above
= 255;
1735 /* Find closest level to level_current */
1736 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1737 l
= device
->brightness
->levels
[i
];
1738 if (abs(l
- level_current
) < abs(delta
)) {
1739 delta
= l
- level_current
;
1744 /* Ajust level_current to closest available level */
1745 level_current
+= delta
;
1746 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1747 l
= device
->brightness
->levels
[i
];
1752 if (l
< min_above
&& l
> level_current
)
1754 if (l
> max_below
&& l
< level_current
)
1759 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1760 return (level_current
< max
) ? min_above
: min
;
1761 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1762 return (level_current
< max
) ? min_above
: max
;
1763 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1764 return (level_current
> min
) ? max_below
: min
;
1765 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1766 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1769 return level_current
;
1774 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1776 unsigned long long level_current
, level_next
;
1777 int result
= -EINVAL
;
1779 if (!device
->brightness
)
1782 result
= acpi_video_device_lcd_get_level_current(device
,
1787 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1789 acpi_video_device_lcd_set_level(device
, level_next
);
1793 printk(KERN_ERR PREFIX
"Failed to switch the brightness\n");
1799 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1800 struct acpi_device
*device
)
1803 struct acpi_device
*dev
;
1805 acpi_video_device_enumerate(video
);
1807 list_for_each_entry(dev
, &device
->children
, node
) {
1809 status
= acpi_video_bus_get_one_device(dev
, video
);
1810 if (ACPI_FAILURE(status
)) {
1811 printk(KERN_WARNING PREFIX
1812 "Cant attach device");
1819 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1822 struct acpi_video_bus
*video
;
1825 if (!device
|| !device
->video
)
1828 video
= device
->video
;
1830 acpi_video_device_remove_fs(device
->dev
);
1832 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1834 acpi_video_device_notify
);
1835 backlight_device_unregister(device
->backlight
);
1837 sysfs_remove_link(&device
->dev
->dev
.kobj
,
1839 sysfs_remove_link(&device
->cdev
->device
.kobj
,
1841 thermal_cooling_device_unregister(device
->cdev
);
1842 device
->cdev
= NULL
;
1844 video_output_unregister(device
->output_dev
);
1849 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1852 struct acpi_video_device
*dev
, *next
;
1854 mutex_lock(&video
->device_list_lock
);
1856 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1858 status
= acpi_video_bus_put_one_device(dev
);
1859 if (ACPI_FAILURE(status
))
1860 printk(KERN_WARNING PREFIX
1861 "hhuuhhuu bug in acpi video driver.\n");
1863 if (dev
->brightness
) {
1864 kfree(dev
->brightness
->levels
);
1865 kfree(dev
->brightness
);
1867 list_del(&dev
->entry
);
1871 mutex_unlock(&video
->device_list_lock
);
1876 /* acpi_video interface */
1878 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1880 return acpi_video_bus_DOS(video
, 0, 0);
1883 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1885 return acpi_video_bus_DOS(video
, 0, 1);
1888 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1890 struct acpi_video_bus
*video
= data
;
1891 struct acpi_device
*device
= NULL
;
1892 struct input_dev
*input
;
1898 device
= video
->device
;
1899 input
= video
->input
;
1902 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1903 * most likely via hotkey. */
1904 acpi_bus_generate_proc_event(device
, event
, 0);
1905 keycode
= KEY_SWITCHVIDEOMODE
;
1908 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1910 acpi_video_device_enumerate(video
);
1911 acpi_video_device_rebind(video
);
1912 acpi_bus_generate_proc_event(device
, event
, 0);
1913 keycode
= KEY_SWITCHVIDEOMODE
;
1916 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1917 acpi_bus_generate_proc_event(device
, event
, 0);
1918 keycode
= KEY_SWITCHVIDEOMODE
;
1920 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1921 acpi_bus_generate_proc_event(device
, event
, 0);
1922 keycode
= KEY_VIDEO_NEXT
;
1924 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1925 acpi_bus_generate_proc_event(device
, event
, 0);
1926 keycode
= KEY_VIDEO_PREV
;
1930 keycode
= KEY_UNKNOWN
;
1931 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1932 "Unsupported event [0x%x]\n", event
));
1936 acpi_notifier_call_chain(device
, event
, 0);
1937 input_report_key(input
, keycode
, 1);
1939 input_report_key(input
, keycode
, 0);
1945 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1947 struct acpi_video_device
*video_device
= data
;
1948 struct acpi_device
*device
= NULL
;
1949 struct acpi_video_bus
*bus
;
1950 struct input_dev
*input
;
1956 device
= video_device
->dev
;
1957 bus
= video_device
->video
;
1961 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1962 if (brightness_switch_enabled
)
1963 acpi_video_switch_brightness(video_device
, event
);
1964 acpi_bus_generate_proc_event(device
, event
, 0);
1965 keycode
= KEY_BRIGHTNESS_CYCLE
;
1967 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1968 if (brightness_switch_enabled
)
1969 acpi_video_switch_brightness(video_device
, event
);
1970 acpi_bus_generate_proc_event(device
, event
, 0);
1971 keycode
= KEY_BRIGHTNESSUP
;
1973 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1974 if (brightness_switch_enabled
)
1975 acpi_video_switch_brightness(video_device
, event
);
1976 acpi_bus_generate_proc_event(device
, event
, 0);
1977 keycode
= KEY_BRIGHTNESSDOWN
;
1979 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1980 if (brightness_switch_enabled
)
1981 acpi_video_switch_brightness(video_device
, event
);
1982 acpi_bus_generate_proc_event(device
, event
, 0);
1983 keycode
= KEY_BRIGHTNESS_ZERO
;
1985 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1986 if (brightness_switch_enabled
)
1987 acpi_video_switch_brightness(video_device
, event
);
1988 acpi_bus_generate_proc_event(device
, event
, 0);
1989 keycode
= KEY_DISPLAY_OFF
;
1992 keycode
= KEY_UNKNOWN
;
1993 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1994 "Unsupported event [0x%x]\n", event
));
1998 acpi_notifier_call_chain(device
, event
, 0);
1999 input_report_key(input
, keycode
, 1);
2001 input_report_key(input
, keycode
, 0);
2007 static int instance
;
2008 static int acpi_video_resume(struct acpi_device
*device
)
2010 struct acpi_video_bus
*video
;
2011 struct acpi_video_device
*video_device
;
2014 if (!device
|| !acpi_driver_data(device
))
2017 video
= acpi_driver_data(device
);
2019 for (i
= 0; i
< video
->attached_count
; i
++) {
2020 video_device
= video
->attached_array
[i
].bind_info
;
2021 if (video_device
&& video_device
->backlight
)
2022 acpi_video_set_brightness(video_device
->backlight
);
2027 static int acpi_video_bus_add(struct acpi_device
*device
)
2030 struct acpi_video_bus
*video
;
2031 struct input_dev
*input
;
2034 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
2038 /* a hack to fix the duplicate name "VID" problem on T61 */
2039 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
2041 device
->pnp
.bus_id
[3] = '0' + instance
;
2044 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2045 if (!strcmp(device
->pnp
.bus_id
, "VGA")) {
2047 device
->pnp
.bus_id
[3] = '0' + instance
;
2051 video
->device
= device
;
2052 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
2053 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
2054 device
->driver_data
= video
;
2056 acpi_video_bus_find_cap(video
);
2057 error
= acpi_video_bus_check(video
);
2059 goto err_free_video
;
2061 error
= acpi_video_bus_add_fs(device
);
2063 goto err_free_video
;
2065 mutex_init(&video
->device_list_lock
);
2066 INIT_LIST_HEAD(&video
->video_device_list
);
2068 acpi_video_bus_get_devices(video
, device
);
2069 acpi_video_bus_start_devices(video
);
2071 status
= acpi_install_notify_handler(device
->handle
,
2073 acpi_video_bus_notify
, video
);
2074 if (ACPI_FAILURE(status
)) {
2075 printk(KERN_ERR PREFIX
2076 "Error installing notify handler\n");
2078 goto err_stop_video
;
2081 video
->input
= input
= input_allocate_device();
2084 goto err_uninstall_notify
;
2087 snprintf(video
->phys
, sizeof(video
->phys
),
2088 "%s/video/input0", acpi_device_hid(video
->device
));
2090 input
->name
= acpi_device_name(video
->device
);
2091 input
->phys
= video
->phys
;
2092 input
->id
.bustype
= BUS_HOST
;
2093 input
->id
.product
= 0x06;
2094 input
->dev
.parent
= &device
->dev
;
2095 input
->evbit
[0] = BIT(EV_KEY
);
2096 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
2097 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
2098 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
2099 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
2100 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
2101 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
2102 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
2103 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
2104 set_bit(KEY_UNKNOWN
, input
->keybit
);
2106 error
= input_register_device(input
);
2108 goto err_free_input_dev
;
2110 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
2111 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
2112 video
->flags
.multihead
? "yes" : "no",
2113 video
->flags
.rom
? "yes" : "no",
2114 video
->flags
.post
? "yes" : "no");
2119 input_free_device(input
);
2120 err_uninstall_notify
:
2121 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
2122 acpi_video_bus_notify
);
2124 acpi_video_bus_stop_devices(video
);
2125 acpi_video_bus_put_devices(video
);
2126 kfree(video
->attached_array
);
2127 acpi_video_bus_remove_fs(device
);
2130 device
->driver_data
= NULL
;
2135 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2137 acpi_status status
= 0;
2138 struct acpi_video_bus
*video
= NULL
;
2141 if (!device
|| !acpi_driver_data(device
))
2144 video
= acpi_driver_data(device
);
2146 acpi_video_bus_stop_devices(video
);
2148 status
= acpi_remove_notify_handler(video
->device
->handle
,
2150 acpi_video_bus_notify
);
2152 acpi_video_bus_put_devices(video
);
2153 acpi_video_bus_remove_fs(device
);
2155 input_unregister_device(video
->input
);
2156 kfree(video
->attached_array
);
2162 static int __init
acpi_video_init(void)
2166 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2167 if (!acpi_video_dir
)
2169 acpi_video_dir
->owner
= THIS_MODULE
;
2171 result
= acpi_bus_register_driver(&acpi_video_bus
);
2173 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2180 static void __exit
acpi_video_exit(void)
2183 acpi_bus_unregister_driver(&acpi_video_bus
);
2185 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2190 module_init(acpi_video_init
);
2191 module_exit(acpi_video_exit
);