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 const 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 const 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 const 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 int acpi_video_bus_write_POST(struct file
*file
,
221 const char __user
*buffer
, size_t count
, loff_t
*data
);
222 static const struct file_operations acpi_video_bus_POST_fops
= {
223 .owner
= THIS_MODULE
,
224 .open
= acpi_video_bus_POST_open_fs
,
226 .write
= acpi_video_bus_write_POST
,
228 .release
= single_release
,
231 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
);
232 static int acpi_video_bus_write_DOS(struct file
*file
,
233 const char __user
*buffer
, size_t count
, loff_t
*data
);
234 static const struct file_operations acpi_video_bus_DOS_fops
= {
235 .owner
= THIS_MODULE
,
236 .open
= acpi_video_bus_DOS_open_fs
,
238 .write
= acpi_video_bus_write_DOS
,
240 .release
= single_release
,
244 static int acpi_video_device_info_open_fs(struct inode
*inode
,
246 static const struct file_operations acpi_video_device_info_fops
= {
247 .owner
= THIS_MODULE
,
248 .open
= acpi_video_device_info_open_fs
,
251 .release
= single_release
,
254 static int acpi_video_device_state_open_fs(struct inode
*inode
,
256 static int acpi_video_device_write_state(struct file
*file
,
257 const char __user
*buffer
, size_t count
, loff_t
*data
);
258 static const struct file_operations acpi_video_device_state_fops
= {
259 .owner
= THIS_MODULE
,
260 .open
= acpi_video_device_state_open_fs
,
262 .write
= acpi_video_device_write_state
,
264 .release
= single_release
,
267 static int acpi_video_device_brightness_open_fs(struct inode
*inode
,
269 static int acpi_video_device_write_brightness(struct file
*file
,
270 const char __user
*buffer
, size_t count
, loff_t
*data
);
271 static struct file_operations acpi_video_device_brightness_fops
= {
272 .owner
= THIS_MODULE
,
273 .open
= acpi_video_device_brightness_open_fs
,
275 .write
= acpi_video_device_write_brightness
,
277 .release
= single_release
,
280 static int acpi_video_device_EDID_open_fs(struct inode
*inode
,
282 static const struct file_operations acpi_video_device_EDID_fops
= {
283 .owner
= THIS_MODULE
,
284 .open
= acpi_video_device_EDID_open_fs
,
287 .release
= single_release
,
290 static const char device_decode
[][30] = {
291 "motherboard VGA device",
297 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
);
298 static void acpi_video_device_rebind(struct acpi_video_bus
*video
);
299 static void acpi_video_device_bind(struct acpi_video_bus
*video
,
300 struct acpi_video_device
*device
);
301 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
);
302 static int acpi_video_device_lcd_set_level(struct acpi_video_device
*device
,
304 static int acpi_video_device_lcd_get_level_current(
305 struct acpi_video_device
*device
,
306 unsigned long long *level
);
307 static int acpi_video_get_next_level(struct acpi_video_device
*device
,
308 u32 level_current
, u32 event
);
309 static void acpi_video_switch_brightness(struct acpi_video_device
*device
,
311 static int acpi_video_device_get_state(struct acpi_video_device
*device
,
312 unsigned long long *state
);
313 static int acpi_video_output_get(struct output_device
*od
);
314 static int acpi_video_device_set_state(struct acpi_video_device
*device
, int state
);
316 /*backlight device sysfs support*/
317 static int acpi_video_get_brightness(struct backlight_device
*bd
)
319 unsigned long long cur_level
;
321 struct acpi_video_device
*vd
=
322 (struct acpi_video_device
*)bl_get_data(bd
);
323 acpi_video_device_lcd_get_level_current(vd
, &cur_level
);
324 for (i
= 2; i
< vd
->brightness
->count
; i
++) {
325 if (vd
->brightness
->levels
[i
] == cur_level
)
326 /* The first two entries are special - see page 575
327 of the ACPI spec 3.0 */
333 static int acpi_video_set_brightness(struct backlight_device
*bd
)
335 int request_level
= bd
->props
.brightness
+2;
336 struct acpi_video_device
*vd
=
337 (struct acpi_video_device
*)bl_get_data(bd
);
338 acpi_video_device_lcd_set_level(vd
,
339 vd
->brightness
->levels
[request_level
]);
343 static struct backlight_ops acpi_backlight_ops
= {
344 .get_brightness
= acpi_video_get_brightness
,
345 .update_status
= acpi_video_set_brightness
,
348 /*video output device sysfs support*/
349 static int acpi_video_output_get(struct output_device
*od
)
351 unsigned long long state
;
352 struct acpi_video_device
*vd
=
353 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
354 acpi_video_device_get_state(vd
, &state
);
358 static int acpi_video_output_set(struct output_device
*od
)
360 unsigned long state
= od
->request_state
;
361 struct acpi_video_device
*vd
=
362 (struct acpi_video_device
*)dev_get_drvdata(&od
->dev
);
363 return acpi_video_device_set_state(vd
, state
);
366 static struct output_properties acpi_output_properties
= {
367 .set_state
= acpi_video_output_set
,
368 .get_status
= acpi_video_output_get
,
372 /* thermal cooling device callbacks */
373 static int video_get_max_state(struct thermal_cooling_device
*cdev
, char *buf
)
375 struct acpi_device
*device
= cdev
->devdata
;
376 struct acpi_video_device
*video
= acpi_driver_data(device
);
378 return sprintf(buf
, "%d\n", video
->brightness
->count
- 3);
381 static int video_get_cur_state(struct thermal_cooling_device
*cdev
, char *buf
)
383 struct acpi_device
*device
= cdev
->devdata
;
384 struct acpi_video_device
*video
= acpi_driver_data(device
);
385 unsigned long long level
;
388 acpi_video_device_lcd_get_level_current(video
, &level
);
389 for (state
= 2; state
< video
->brightness
->count
; state
++)
390 if (level
== video
->brightness
->levels
[state
])
391 return sprintf(buf
, "%d\n",
392 video
->brightness
->count
- state
- 1);
398 video_set_cur_state(struct thermal_cooling_device
*cdev
, unsigned int state
)
400 struct acpi_device
*device
= cdev
->devdata
;
401 struct acpi_video_device
*video
= acpi_driver_data(device
);
404 if ( state
>= video
->brightness
->count
- 2)
407 state
= video
->brightness
->count
- state
;
408 level
= video
->brightness
->levels
[state
-1];
409 return acpi_video_device_lcd_set_level(video
, level
);
412 static struct thermal_cooling_device_ops video_cooling_ops
= {
413 .get_max_state
= video_get_max_state
,
414 .get_cur_state
= video_get_cur_state
,
415 .set_cur_state
= video_set_cur_state
,
418 /* --------------------------------------------------------------------------
420 -------------------------------------------------------------------------- */
425 acpi_video_device_query(struct acpi_video_device
*device
, unsigned long long *state
)
429 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DGS", NULL
, state
);
435 acpi_video_device_get_state(struct acpi_video_device
*device
,
436 unsigned long long *state
)
440 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DCS", NULL
, state
);
446 acpi_video_device_set_state(struct acpi_video_device
*device
, int state
)
449 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
450 struct acpi_object_list args
= { 1, &arg0
};
451 unsigned long long ret
;
454 arg0
.integer
.value
= state
;
455 status
= acpi_evaluate_integer(device
->dev
->handle
, "_DSS", &args
, &ret
);
461 acpi_video_device_lcd_query_levels(struct acpi_video_device
*device
,
462 union acpi_object
**levels
)
465 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
466 union acpi_object
*obj
;
471 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCL", NULL
, &buffer
);
472 if (!ACPI_SUCCESS(status
))
474 obj
= (union acpi_object
*)buffer
.pointer
;
475 if (!obj
|| (obj
->type
!= ACPI_TYPE_PACKAGE
)) {
476 printk(KERN_ERR PREFIX
"Invalid _BCL data\n");
486 kfree(buffer
.pointer
);
492 acpi_video_device_lcd_set_level(struct acpi_video_device
*device
, int level
)
495 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
496 struct acpi_object_list args
= { 1, &arg0
};
500 arg0
.integer
.value
= level
;
502 if (device
->cap
._BCM
)
503 status
= acpi_evaluate_object(device
->dev
->handle
, "_BCM",
505 device
->brightness
->curr
= level
;
506 for (state
= 2; state
< device
->brightness
->count
; state
++)
507 if (level
== device
->brightness
->levels
[state
])
508 device
->backlight
->props
.brightness
= state
- 2;
514 acpi_video_device_lcd_get_level_current(struct acpi_video_device
*device
,
515 unsigned long long *level
)
517 if (device
->cap
._BQC
)
518 return acpi_evaluate_integer(device
->dev
->handle
, "_BQC", NULL
,
520 *level
= device
->brightness
->curr
;
525 acpi_video_device_EDID(struct acpi_video_device
*device
,
526 union acpi_object
**edid
, ssize_t length
)
529 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
530 union acpi_object
*obj
;
531 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
532 struct acpi_object_list args
= { 1, &arg0
};
540 arg0
.integer
.value
= 1;
541 else if (length
== 256)
542 arg0
.integer
.value
= 2;
546 status
= acpi_evaluate_object(device
->dev
->handle
, "_DDC", &args
, &buffer
);
547 if (ACPI_FAILURE(status
))
550 obj
= buffer
.pointer
;
552 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
)
555 printk(KERN_ERR PREFIX
"Invalid _DDC data\n");
566 acpi_video_bus_set_POST(struct acpi_video_bus
*video
, unsigned long option
)
569 unsigned long long tmp
;
570 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
571 struct acpi_object_list args
= { 1, &arg0
};
574 arg0
.integer
.value
= option
;
576 status
= acpi_evaluate_integer(video
->device
->handle
, "_SPD", &args
, &tmp
);
577 if (ACPI_SUCCESS(status
))
578 status
= tmp
? (-EINVAL
) : (AE_OK
);
584 acpi_video_bus_get_POST(struct acpi_video_bus
*video
, unsigned long long *id
)
588 status
= acpi_evaluate_integer(video
->device
->handle
, "_GPD", NULL
, id
);
594 acpi_video_bus_POST_options(struct acpi_video_bus
*video
,
595 unsigned long long *options
)
599 status
= acpi_evaluate_integer(video
->device
->handle
, "_VPO", NULL
, options
);
607 * video : video bus device pointer
609 * 0. The system BIOS should NOT automatically switch(toggle)
610 * the active display output.
611 * 1. The system BIOS should automatically switch (toggle) the
612 * active display output. No switch event.
613 * 2. The _DGS value should be locked.
614 * 3. The system BIOS should not automatically switch (toggle) the
615 * active display output, but instead generate the display switch
618 * 0. The system BIOS should automatically control the brightness level
619 * of the LCD when the power changes from AC to DC
620 * 1. The system BIOS should NOT automatically control the brightness
621 * level of the LCD when the power changes from AC to DC.
627 acpi_video_bus_DOS(struct acpi_video_bus
*video
, int bios_flag
, int lcd_flag
)
629 acpi_integer status
= 0;
630 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
631 struct acpi_object_list args
= { 1, &arg0
};
634 if (bios_flag
< 0 || bios_flag
> 3 || lcd_flag
< 0 || lcd_flag
> 1) {
638 arg0
.integer
.value
= (lcd_flag
<< 2) | bios_flag
;
639 video
->dos_setting
= arg0
.integer
.value
;
640 acpi_evaluate_object(video
->device
->handle
, "_DOS", &args
, NULL
);
647 * Simple comparison function used to sort backlight levels.
651 acpi_video_cmp_level(const void *a
, const void *b
)
653 return *(int *)a
- *(int *)b
;
658 * device : video output device (LCD, CRT, ..)
661 * Maximum brightness level
663 * Allocate and initialize device->brightness.
667 acpi_video_init_brightness(struct acpi_video_device
*device
)
669 union acpi_object
*obj
= NULL
;
670 int i
, max_level
= 0, count
= 0;
671 union acpi_object
*o
;
672 struct acpi_video_device_brightness
*br
= NULL
;
674 if (!ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device
, &obj
))) {
675 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Could not query available "
676 "LCD brightness level\n"));
680 if (obj
->package
.count
< 2)
683 br
= kzalloc(sizeof(*br
), GFP_KERNEL
);
685 printk(KERN_ERR
"can't allocate memory\n");
689 br
->levels
= kmalloc(obj
->package
.count
* sizeof *(br
->levels
),
694 for (i
= 0; i
< obj
->package
.count
; i
++) {
695 o
= (union acpi_object
*)&obj
->package
.elements
[i
];
696 if (o
->type
!= ACPI_TYPE_INTEGER
) {
697 printk(KERN_ERR PREFIX
"Invalid data\n");
700 br
->levels
[count
] = (u32
) o
->integer
.value
;
702 if (br
->levels
[count
] > max_level
)
703 max_level
= br
->levels
[count
];
707 /* don't sort the first two brightness levels */
708 sort(&br
->levels
[2], count
- 2, sizeof(br
->levels
[2]),
709 acpi_video_cmp_level
, NULL
);
712 goto out_free_levels
;
715 device
->brightness
= br
;
716 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "found %d brightness levels\n", count
));
725 device
->brightness
= NULL
;
732 * device : video output device (LCD, CRT, ..)
737 * Find out all required AML methods defined under the output
741 static void acpi_video_device_find_cap(struct acpi_video_device
*device
)
743 acpi_handle h_dummy1
;
747 memset(&device
->cap
, 0, sizeof(device
->cap
));
749 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_ADR", &h_dummy1
))) {
750 device
->cap
._ADR
= 1;
752 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCL", &h_dummy1
))) {
753 device
->cap
._BCL
= 1;
755 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_BCM", &h_dummy1
))) {
756 device
->cap
._BCM
= 1;
758 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
,"_BQC",&h_dummy1
)))
759 device
->cap
._BQC
= 1;
760 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DDC", &h_dummy1
))) {
761 device
->cap
._DDC
= 1;
763 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DCS", &h_dummy1
))) {
764 device
->cap
._DCS
= 1;
766 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DGS", &h_dummy1
))) {
767 device
->cap
._DGS
= 1;
769 if (ACPI_SUCCESS(acpi_get_handle(device
->dev
->handle
, "_DSS", &h_dummy1
))) {
770 device
->cap
._DSS
= 1;
773 if (acpi_video_backlight_support())
774 max_level
= acpi_video_init_brightness(device
);
776 if (device
->cap
._BCL
&& device
->cap
._BCM
&& max_level
> 0) {
778 static int count
= 0;
780 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
784 sprintf(name
, "acpi_video%d", count
++);
785 device
->backlight
= backlight_device_register(name
,
786 NULL
, device
, &acpi_backlight_ops
);
787 device
->backlight
->props
.max_brightness
= device
->brightness
->count
-3;
789 * If there exists the _BQC object, the _BQC object will be
790 * called to get the current backlight brightness. Otherwise
791 * the brightness will be set to the maximum.
793 if (device
->cap
._BQC
)
794 device
->backlight
->props
.brightness
=
795 acpi_video_get_brightness(device
->backlight
);
797 device
->backlight
->props
.brightness
=
798 device
->backlight
->props
.max_brightness
;
799 backlight_update_status(device
->backlight
);
802 device
->cdev
= thermal_cooling_device_register("LCD",
803 device
->dev
, &video_cooling_ops
);
804 if (IS_ERR(device
->cdev
))
807 dev_info(&device
->dev
->dev
, "registered as cooling_device%d\n",
809 result
= sysfs_create_link(&device
->dev
->dev
.kobj
,
810 &device
->cdev
->device
.kobj
,
813 printk(KERN_ERR PREFIX
"Create sysfs link\n");
814 result
= sysfs_create_link(&device
->cdev
->device
.kobj
,
815 &device
->dev
->dev
.kobj
, "device");
817 printk(KERN_ERR PREFIX
"Create sysfs link\n");
821 if (acpi_video_display_switch_support()) {
823 if (device
->cap
._DCS
&& device
->cap
._DSS
) {
826 name
= kzalloc(MAX_NAME_LEN
, GFP_KERNEL
);
829 sprintf(name
, "acpi_video%d", count
++);
830 device
->output_dev
= video_output_register(name
,
831 NULL
, device
, &acpi_output_properties
);
839 * device : video output device (VGA)
844 * Find out all required AML methods defined under the video bus device.
847 static void acpi_video_bus_find_cap(struct acpi_video_bus
*video
)
849 acpi_handle h_dummy1
;
851 memset(&video
->cap
, 0, sizeof(video
->cap
));
852 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOS", &h_dummy1
))) {
855 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_DOD", &h_dummy1
))) {
858 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_ROM", &h_dummy1
))) {
861 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_GPD", &h_dummy1
))) {
864 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_SPD", &h_dummy1
))) {
867 if (ACPI_SUCCESS(acpi_get_handle(video
->device
->handle
, "_VPO", &h_dummy1
))) {
873 * Check whether the video bus device has required AML method to
874 * support the desired features
877 static int acpi_video_bus_check(struct acpi_video_bus
*video
)
879 acpi_status status
= -ENOENT
;
885 dev
= acpi_get_physical_pci_device(video
->device
->handle
);
890 /* Since there is no HID, CID and so on for VGA driver, we have
891 * to check well known required nodes.
894 /* Does this device support video switching? */
895 if (video
->cap
._DOS
) {
896 video
->flags
.multihead
= 1;
900 /* Does this device support retrieving a video ROM? */
901 if (video
->cap
._ROM
) {
902 video
->flags
.rom
= 1;
906 /* Does this device support configuring which video device to POST? */
907 if (video
->cap
._GPD
&& video
->cap
._SPD
&& video
->cap
._VPO
) {
908 video
->flags
.post
= 1;
915 /* --------------------------------------------------------------------------
917 -------------------------------------------------------------------------- */
919 static struct proc_dir_entry
*acpi_video_dir
;
923 static int acpi_video_device_info_seq_show(struct seq_file
*seq
, void *offset
)
925 struct acpi_video_device
*dev
= seq
->private;
931 seq_printf(seq
, "device_id: 0x%04x\n", (u32
) dev
->device_id
);
932 seq_printf(seq
, "type: ");
934 seq_printf(seq
, "CRT\n");
935 else if (dev
->flags
.lcd
)
936 seq_printf(seq
, "LCD\n");
937 else if (dev
->flags
.tvout
)
938 seq_printf(seq
, "TVOUT\n");
939 else if (dev
->flags
.dvi
)
940 seq_printf(seq
, "DVI\n");
942 seq_printf(seq
, "UNKNOWN\n");
944 seq_printf(seq
, "known by bios: %s\n", dev
->flags
.bios
? "yes" : "no");
951 acpi_video_device_info_open_fs(struct inode
*inode
, struct file
*file
)
953 return single_open(file
, acpi_video_device_info_seq_show
,
957 static int acpi_video_device_state_seq_show(struct seq_file
*seq
, void *offset
)
960 struct acpi_video_device
*dev
= seq
->private;
961 unsigned long long state
;
967 status
= acpi_video_device_get_state(dev
, &state
);
968 seq_printf(seq
, "state: ");
969 if (ACPI_SUCCESS(status
))
970 seq_printf(seq
, "0x%02llx\n", state
);
972 seq_printf(seq
, "<not supported>\n");
974 status
= acpi_video_device_query(dev
, &state
);
975 seq_printf(seq
, "query: ");
976 if (ACPI_SUCCESS(status
))
977 seq_printf(seq
, "0x%02llx\n", state
);
979 seq_printf(seq
, "<not supported>\n");
986 acpi_video_device_state_open_fs(struct inode
*inode
, struct file
*file
)
988 return single_open(file
, acpi_video_device_state_seq_show
,
993 acpi_video_device_write_state(struct file
*file
,
994 const char __user
* buffer
,
995 size_t count
, loff_t
* data
)
998 struct seq_file
*m
= file
->private_data
;
999 struct acpi_video_device
*dev
= m
->private;
1000 char str
[12] = { 0 };
1004 if (!dev
|| count
+ 1 > sizeof str
)
1007 if (copy_from_user(str
, buffer
, count
))
1011 state
= simple_strtoul(str
, NULL
, 0);
1012 state
&= ((1ul << 31) | (1ul << 30) | (1ul << 0));
1014 status
= acpi_video_device_set_state(dev
, state
);
1023 acpi_video_device_brightness_seq_show(struct seq_file
*seq
, void *offset
)
1025 struct acpi_video_device
*dev
= seq
->private;
1029 if (!dev
|| !dev
->brightness
) {
1030 seq_printf(seq
, "<not supported>\n");
1034 seq_printf(seq
, "levels: ");
1035 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1036 seq_printf(seq
, " %d", dev
->brightness
->levels
[i
]);
1037 seq_printf(seq
, "\ncurrent: %d\n", dev
->brightness
->curr
);
1043 acpi_video_device_brightness_open_fs(struct inode
*inode
, struct file
*file
)
1045 return single_open(file
, acpi_video_device_brightness_seq_show
,
1050 acpi_video_device_write_brightness(struct file
*file
,
1051 const char __user
* buffer
,
1052 size_t count
, loff_t
* data
)
1054 struct seq_file
*m
= file
->private_data
;
1055 struct acpi_video_device
*dev
= m
->private;
1056 char str
[5] = { 0 };
1057 unsigned int level
= 0;
1061 if (!dev
|| !dev
->brightness
|| count
+ 1 > sizeof str
)
1064 if (copy_from_user(str
, buffer
, count
))
1068 level
= simple_strtoul(str
, NULL
, 0);
1073 /* validate through the list of available levels */
1074 for (i
= 2; i
< dev
->brightness
->count
; i
++)
1075 if (level
== dev
->brightness
->levels
[i
]) {
1077 (acpi_video_device_lcd_set_level(dev
, level
)))
1078 dev
->brightness
->curr
= level
;
1085 static int acpi_video_device_EDID_seq_show(struct seq_file
*seq
, void *offset
)
1087 struct acpi_video_device
*dev
= seq
->private;
1090 union acpi_object
*edid
= NULL
;
1096 status
= acpi_video_device_EDID(dev
, &edid
, 128);
1097 if (ACPI_FAILURE(status
)) {
1098 status
= acpi_video_device_EDID(dev
, &edid
, 256);
1101 if (ACPI_FAILURE(status
)) {
1105 if (edid
&& edid
->type
== ACPI_TYPE_BUFFER
) {
1106 for (i
= 0; i
< edid
->buffer
.length
; i
++)
1107 seq_putc(seq
, edid
->buffer
.pointer
[i
]);
1112 seq_printf(seq
, "<not supported>\n");
1120 acpi_video_device_EDID_open_fs(struct inode
*inode
, struct file
*file
)
1122 return single_open(file
, acpi_video_device_EDID_seq_show
,
1126 static int acpi_video_device_add_fs(struct acpi_device
*device
)
1128 struct proc_dir_entry
*entry
, *device_dir
;
1129 struct acpi_video_device
*vid_dev
;
1131 vid_dev
= acpi_driver_data(device
);
1135 device_dir
= proc_mkdir(acpi_device_bid(device
),
1136 vid_dev
->video
->dir
);
1140 device_dir
->owner
= THIS_MODULE
;
1143 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1144 &acpi_video_device_info_fops
, acpi_driver_data(device
));
1146 goto err_remove_dir
;
1149 entry
= proc_create_data("state", S_IFREG
| S_IRUGO
| S_IWUSR
,
1151 &acpi_video_device_state_fops
,
1152 acpi_driver_data(device
));
1154 goto err_remove_info
;
1156 /* 'brightness' [R/W] */
1157 entry
= proc_create_data("brightness", S_IFREG
| S_IRUGO
| S_IWUSR
,
1159 &acpi_video_device_brightness_fops
,
1160 acpi_driver_data(device
));
1162 goto err_remove_state
;
1165 entry
= proc_create_data("EDID", S_IRUGO
, device_dir
,
1166 &acpi_video_device_EDID_fops
,
1167 acpi_driver_data(device
));
1169 goto err_remove_brightness
;
1171 acpi_device_dir(device
) = device_dir
;
1175 err_remove_brightness
:
1176 remove_proc_entry("brightness", device_dir
);
1178 remove_proc_entry("state", device_dir
);
1180 remove_proc_entry("info", device_dir
);
1182 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1186 static int acpi_video_device_remove_fs(struct acpi_device
*device
)
1188 struct acpi_video_device
*vid_dev
;
1189 struct proc_dir_entry
*device_dir
;
1191 vid_dev
= acpi_driver_data(device
);
1192 if (!vid_dev
|| !vid_dev
->video
|| !vid_dev
->video
->dir
)
1195 device_dir
= acpi_device_dir(device
);
1197 remove_proc_entry("info", device_dir
);
1198 remove_proc_entry("state", device_dir
);
1199 remove_proc_entry("brightness", device_dir
);
1200 remove_proc_entry("EDID", device_dir
);
1201 remove_proc_entry(acpi_device_bid(device
), vid_dev
->video
->dir
);
1202 acpi_device_dir(device
) = NULL
;
1209 static int acpi_video_bus_info_seq_show(struct seq_file
*seq
, void *offset
)
1211 struct acpi_video_bus
*video
= seq
->private;
1217 seq_printf(seq
, "Switching heads: %s\n",
1218 video
->flags
.multihead
? "yes" : "no");
1219 seq_printf(seq
, "Video ROM: %s\n",
1220 video
->flags
.rom
? "yes" : "no");
1221 seq_printf(seq
, "Device to be POSTed on boot: %s\n",
1222 video
->flags
.post
? "yes" : "no");
1228 static int acpi_video_bus_info_open_fs(struct inode
*inode
, struct file
*file
)
1230 return single_open(file
, acpi_video_bus_info_seq_show
,
1234 static int acpi_video_bus_ROM_seq_show(struct seq_file
*seq
, void *offset
)
1236 struct acpi_video_bus
*video
= seq
->private;
1242 printk(KERN_INFO PREFIX
"Please implement %s\n", __func__
);
1243 seq_printf(seq
, "<TODO>\n");
1249 static int acpi_video_bus_ROM_open_fs(struct inode
*inode
, struct file
*file
)
1251 return single_open(file
, acpi_video_bus_ROM_seq_show
, PDE(inode
)->data
);
1254 static int acpi_video_bus_POST_info_seq_show(struct seq_file
*seq
, void *offset
)
1256 struct acpi_video_bus
*video
= seq
->private;
1257 unsigned long long options
;
1264 status
= acpi_video_bus_POST_options(video
, &options
);
1265 if (ACPI_SUCCESS(status
)) {
1266 if (!(options
& 1)) {
1267 printk(KERN_WARNING PREFIX
1268 "The motherboard VGA device is not listed as a possible POST device.\n");
1269 printk(KERN_WARNING PREFIX
1270 "This indicates a BIOS bug. Please contact the manufacturer.\n");
1272 printk(KERN_WARNING
"%llx\n", options
);
1273 seq_printf(seq
, "can POST: <integrated video>");
1275 seq_printf(seq
, " <PCI video>");
1277 seq_printf(seq
, " <AGP video>");
1278 seq_putc(seq
, '\n');
1280 seq_printf(seq
, "<not supported>\n");
1286 acpi_video_bus_POST_info_open_fs(struct inode
*inode
, struct file
*file
)
1288 return single_open(file
, acpi_video_bus_POST_info_seq_show
,
1292 static int acpi_video_bus_POST_seq_show(struct seq_file
*seq
, void *offset
)
1294 struct acpi_video_bus
*video
= seq
->private;
1296 unsigned long long id
;
1302 status
= acpi_video_bus_get_POST(video
, &id
);
1303 if (!ACPI_SUCCESS(status
)) {
1304 seq_printf(seq
, "<not supported>\n");
1307 seq_printf(seq
, "device POSTed is <%s>\n", device_decode
[id
& 3]);
1313 static int acpi_video_bus_DOS_seq_show(struct seq_file
*seq
, void *offset
)
1315 struct acpi_video_bus
*video
= seq
->private;
1318 seq_printf(seq
, "DOS setting: <%d>\n", video
->dos_setting
);
1323 static int acpi_video_bus_POST_open_fs(struct inode
*inode
, struct file
*file
)
1325 return single_open(file
, acpi_video_bus_POST_seq_show
,
1329 static int acpi_video_bus_DOS_open_fs(struct inode
*inode
, struct file
*file
)
1331 return single_open(file
, acpi_video_bus_DOS_seq_show
, PDE(inode
)->data
);
1335 acpi_video_bus_write_POST(struct file
*file
,
1336 const char __user
* buffer
,
1337 size_t count
, loff_t
* data
)
1340 struct seq_file
*m
= file
->private_data
;
1341 struct acpi_video_bus
*video
= m
->private;
1342 char str
[12] = { 0 };
1343 unsigned long long opt
, options
;
1346 if (!video
|| count
+ 1 > sizeof str
)
1349 status
= acpi_video_bus_POST_options(video
, &options
);
1350 if (!ACPI_SUCCESS(status
))
1353 if (copy_from_user(str
, buffer
, count
))
1357 opt
= strtoul(str
, NULL
, 0);
1361 /* just in case an OEM 'forgot' the motherboard... */
1364 if (options
& (1ul << opt
)) {
1365 status
= acpi_video_bus_set_POST(video
, opt
);
1366 if (!ACPI_SUCCESS(status
))
1375 acpi_video_bus_write_DOS(struct file
*file
,
1376 const char __user
* buffer
,
1377 size_t count
, loff_t
* data
)
1380 struct seq_file
*m
= file
->private_data
;
1381 struct acpi_video_bus
*video
= m
->private;
1382 char str
[12] = { 0 };
1386 if (!video
|| count
+ 1 > sizeof str
)
1389 if (copy_from_user(str
, buffer
, count
))
1393 opt
= strtoul(str
, NULL
, 0);
1397 status
= acpi_video_bus_DOS(video
, opt
& 0x3, (opt
& 0x4) >> 2);
1399 if (!ACPI_SUCCESS(status
))
1405 static int acpi_video_bus_add_fs(struct acpi_device
*device
)
1407 struct acpi_video_bus
*video
= acpi_driver_data(device
);
1408 struct proc_dir_entry
*device_dir
;
1409 struct proc_dir_entry
*entry
;
1411 device_dir
= proc_mkdir(acpi_device_bid(device
), acpi_video_dir
);
1415 device_dir
->owner
= THIS_MODULE
;
1418 entry
= proc_create_data("info", S_IRUGO
, device_dir
,
1419 &acpi_video_bus_info_fops
,
1420 acpi_driver_data(device
));
1422 goto err_remove_dir
;
1425 entry
= proc_create_data("ROM", S_IRUGO
, device_dir
,
1426 &acpi_video_bus_ROM_fops
,
1427 acpi_driver_data(device
));
1429 goto err_remove_info
;
1431 /* 'POST_info' [R] */
1432 entry
= proc_create_data("POST_info", S_IRUGO
, device_dir
,
1433 &acpi_video_bus_POST_info_fops
,
1434 acpi_driver_data(device
));
1436 goto err_remove_rom
;
1439 entry
= proc_create_data("POST", S_IFREG
| S_IRUGO
| S_IWUSR
,
1441 &acpi_video_bus_POST_fops
,
1442 acpi_driver_data(device
));
1444 goto err_remove_post_info
;
1447 entry
= proc_create_data("DOS", S_IFREG
| S_IRUGO
| S_IWUSR
,
1449 &acpi_video_bus_DOS_fops
,
1450 acpi_driver_data(device
));
1452 goto err_remove_post
;
1454 video
->dir
= acpi_device_dir(device
) = device_dir
;
1458 remove_proc_entry("POST", device_dir
);
1459 err_remove_post_info
:
1460 remove_proc_entry("POST_info", device_dir
);
1462 remove_proc_entry("ROM", device_dir
);
1464 remove_proc_entry("info", device_dir
);
1466 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1470 static int acpi_video_bus_remove_fs(struct acpi_device
*device
)
1472 struct proc_dir_entry
*device_dir
= acpi_device_dir(device
);
1475 remove_proc_entry("info", device_dir
);
1476 remove_proc_entry("ROM", device_dir
);
1477 remove_proc_entry("POST_info", device_dir
);
1478 remove_proc_entry("POST", device_dir
);
1479 remove_proc_entry("DOS", device_dir
);
1480 remove_proc_entry(acpi_device_bid(device
), acpi_video_dir
);
1481 acpi_device_dir(device
) = NULL
;
1487 /* --------------------------------------------------------------------------
1489 -------------------------------------------------------------------------- */
1491 /* device interface */
1492 static struct acpi_video_device_attrib
*
1493 acpi_video_get_device_attr(struct acpi_video_bus
*video
, unsigned long device_id
)
1495 struct acpi_video_enumerated_device
*ids
;
1498 for (i
= 0; i
< video
->attached_count
; i
++) {
1499 ids
= &video
->attached_array
[i
];
1500 if ((ids
->value
.int_val
& 0xffff) == device_id
)
1501 return &ids
->value
.attrib
;
1508 acpi_video_bus_get_one_device(struct acpi_device
*device
,
1509 struct acpi_video_bus
*video
)
1511 unsigned long long device_id
;
1513 struct acpi_video_device
*data
;
1514 struct acpi_video_device_attrib
* attribute
;
1516 if (!device
|| !video
)
1520 acpi_evaluate_integer(device
->handle
, "_ADR", NULL
, &device_id
);
1521 if (ACPI_SUCCESS(status
)) {
1523 data
= kzalloc(sizeof(struct acpi_video_device
), GFP_KERNEL
);
1527 strcpy(acpi_device_name(device
), ACPI_VIDEO_DEVICE_NAME
);
1528 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
1529 device
->driver_data
= data
;
1531 data
->device_id
= device_id
;
1532 data
->video
= video
;
1535 attribute
= acpi_video_get_device_attr(video
, device_id
);
1537 if((attribute
!= NULL
) && attribute
->device_id_scheme
) {
1538 switch (attribute
->display_type
) {
1539 case ACPI_VIDEO_DISPLAY_CRT
:
1540 data
->flags
.crt
= 1;
1542 case ACPI_VIDEO_DISPLAY_TV
:
1543 data
->flags
.tvout
= 1;
1545 case ACPI_VIDEO_DISPLAY_DVI
:
1546 data
->flags
.dvi
= 1;
1548 case ACPI_VIDEO_DISPLAY_LCD
:
1549 data
->flags
.lcd
= 1;
1552 data
->flags
.unknown
= 1;
1555 if(attribute
->bios_can_detect
)
1556 data
->flags
.bios
= 1;
1558 data
->flags
.unknown
= 1;
1560 acpi_video_device_bind(video
, data
);
1561 acpi_video_device_find_cap(data
);
1563 status
= acpi_install_notify_handler(device
->handle
,
1565 acpi_video_device_notify
,
1567 if (ACPI_FAILURE(status
)) {
1568 printk(KERN_ERR PREFIX
1569 "Error installing notify handler\n");
1570 if(data
->brightness
)
1571 kfree(data
->brightness
->levels
);
1572 kfree(data
->brightness
);
1577 mutex_lock(&video
->device_list_lock
);
1578 list_add_tail(&data
->entry
, &video
->video_device_list
);
1579 mutex_unlock(&video
->device_list_lock
);
1581 acpi_video_device_add_fs(device
);
1591 * video : video bus device
1596 * Enumerate the video device list of the video bus,
1597 * bind the ids with the corresponding video devices
1598 * under the video bus.
1601 static void acpi_video_device_rebind(struct acpi_video_bus
*video
)
1603 struct acpi_video_device
*dev
;
1605 mutex_lock(&video
->device_list_lock
);
1607 list_for_each_entry(dev
, &video
->video_device_list
, entry
)
1608 acpi_video_device_bind(video
, dev
);
1610 mutex_unlock(&video
->device_list_lock
);
1615 * video : video bus device
1616 * device : video output device under the video
1622 * Bind the ids with the corresponding video devices
1623 * under the video bus.
1627 acpi_video_device_bind(struct acpi_video_bus
*video
,
1628 struct acpi_video_device
*device
)
1630 struct acpi_video_enumerated_device
*ids
;
1633 for (i
= 0; i
< video
->attached_count
; i
++) {
1634 ids
= &video
->attached_array
[i
];
1635 if (device
->device_id
== (ids
->value
.int_val
& 0xffff)) {
1636 ids
->bind_info
= device
;
1637 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "device_bind %d\n", i
));
1644 * video : video bus device
1649 * Call _DOD to enumerate all devices attached to display adapter
1653 static int acpi_video_device_enumerate(struct acpi_video_bus
*video
)
1658 struct acpi_video_enumerated_device
*active_list
;
1659 struct acpi_buffer buffer
= { ACPI_ALLOCATE_BUFFER
, NULL
};
1660 union acpi_object
*dod
= NULL
;
1661 union acpi_object
*obj
;
1663 status
= acpi_evaluate_object(video
->device
->handle
, "_DOD", NULL
, &buffer
);
1664 if (!ACPI_SUCCESS(status
)) {
1665 ACPI_EXCEPTION((AE_INFO
, status
, "Evaluating _DOD"));
1669 dod
= buffer
.pointer
;
1670 if (!dod
|| (dod
->type
!= ACPI_TYPE_PACKAGE
)) {
1671 ACPI_EXCEPTION((AE_INFO
, status
, "Invalid _DOD data"));
1676 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d video heads in _DOD\n",
1677 dod
->package
.count
));
1679 active_list
= kcalloc(1 + dod
->package
.count
,
1680 sizeof(struct acpi_video_enumerated_device
),
1688 for (i
= 0; i
< dod
->package
.count
; i
++) {
1689 obj
= &dod
->package
.elements
[i
];
1691 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
1692 printk(KERN_ERR PREFIX
1693 "Invalid _DOD data in element %d\n", i
);
1697 active_list
[count
].value
.int_val
= obj
->integer
.value
;
1698 active_list
[count
].bind_info
= NULL
;
1699 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "dod element[%d] = %d\n", i
,
1700 (int)obj
->integer
.value
));
1704 kfree(video
->attached_array
);
1706 video
->attached_array
= active_list
;
1707 video
->attached_count
= count
;
1710 kfree(buffer
.pointer
);
1715 acpi_video_get_next_level(struct acpi_video_device
*device
,
1716 u32 level_current
, u32 event
)
1718 int min
, max
, min_above
, max_below
, i
, l
, delta
= 255;
1719 max
= max_below
= 0;
1720 min
= min_above
= 255;
1721 /* Find closest level to level_current */
1722 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1723 l
= device
->brightness
->levels
[i
];
1724 if (abs(l
- level_current
) < abs(delta
)) {
1725 delta
= l
- level_current
;
1730 /* Ajust level_current to closest available level */
1731 level_current
+= delta
;
1732 for (i
= 2; i
< device
->brightness
->count
; i
++) {
1733 l
= device
->brightness
->levels
[i
];
1738 if (l
< min_above
&& l
> level_current
)
1740 if (l
> max_below
&& l
< level_current
)
1745 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
:
1746 return (level_current
< max
) ? min_above
: min
;
1747 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
:
1748 return (level_current
< max
) ? min_above
: max
;
1749 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
:
1750 return (level_current
> min
) ? max_below
: min
;
1751 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
:
1752 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
:
1755 return level_current
;
1760 acpi_video_switch_brightness(struct acpi_video_device
*device
, int event
)
1762 unsigned long long level_current
, level_next
;
1763 if (!device
->brightness
)
1765 acpi_video_device_lcd_get_level_current(device
, &level_current
);
1766 level_next
= acpi_video_get_next_level(device
, level_current
, event
);
1767 acpi_video_device_lcd_set_level(device
, level_next
);
1771 acpi_video_bus_get_devices(struct acpi_video_bus
*video
,
1772 struct acpi_device
*device
)
1775 struct acpi_device
*dev
;
1777 acpi_video_device_enumerate(video
);
1779 list_for_each_entry(dev
, &device
->children
, node
) {
1781 status
= acpi_video_bus_get_one_device(dev
, video
);
1782 if (ACPI_FAILURE(status
)) {
1783 printk(KERN_WARNING PREFIX
1784 "Cant attach device");
1791 static int acpi_video_bus_put_one_device(struct acpi_video_device
*device
)
1794 struct acpi_video_bus
*video
;
1797 if (!device
|| !device
->video
)
1800 video
= device
->video
;
1802 acpi_video_device_remove_fs(device
->dev
);
1804 status
= acpi_remove_notify_handler(device
->dev
->handle
,
1806 acpi_video_device_notify
);
1807 backlight_device_unregister(device
->backlight
);
1809 sysfs_remove_link(&device
->dev
->dev
.kobj
,
1811 sysfs_remove_link(&device
->cdev
->device
.kobj
,
1813 thermal_cooling_device_unregister(device
->cdev
);
1814 device
->cdev
= NULL
;
1816 video_output_unregister(device
->output_dev
);
1821 static int acpi_video_bus_put_devices(struct acpi_video_bus
*video
)
1824 struct acpi_video_device
*dev
, *next
;
1826 mutex_lock(&video
->device_list_lock
);
1828 list_for_each_entry_safe(dev
, next
, &video
->video_device_list
, entry
) {
1830 status
= acpi_video_bus_put_one_device(dev
);
1831 if (ACPI_FAILURE(status
))
1832 printk(KERN_WARNING PREFIX
1833 "hhuuhhuu bug in acpi video driver.\n");
1835 if (dev
->brightness
) {
1836 kfree(dev
->brightness
->levels
);
1837 kfree(dev
->brightness
);
1839 list_del(&dev
->entry
);
1843 mutex_unlock(&video
->device_list_lock
);
1848 /* acpi_video interface */
1850 static int acpi_video_bus_start_devices(struct acpi_video_bus
*video
)
1852 return acpi_video_bus_DOS(video
, 0, 0);
1855 static int acpi_video_bus_stop_devices(struct acpi_video_bus
*video
)
1857 return acpi_video_bus_DOS(video
, 0, 1);
1860 static void acpi_video_bus_notify(acpi_handle handle
, u32 event
, void *data
)
1862 struct acpi_video_bus
*video
= data
;
1863 struct acpi_device
*device
= NULL
;
1864 struct input_dev
*input
;
1870 device
= video
->device
;
1871 input
= video
->input
;
1874 case ACPI_VIDEO_NOTIFY_SWITCH
: /* User requested a switch,
1875 * most likely via hotkey. */
1876 acpi_bus_generate_proc_event(device
, event
, 0);
1877 keycode
= KEY_SWITCHVIDEOMODE
;
1880 case ACPI_VIDEO_NOTIFY_PROBE
: /* User plugged in or removed a video
1882 acpi_video_device_enumerate(video
);
1883 acpi_video_device_rebind(video
);
1884 acpi_bus_generate_proc_event(device
, event
, 0);
1885 keycode
= KEY_SWITCHVIDEOMODE
;
1888 case ACPI_VIDEO_NOTIFY_CYCLE
: /* Cycle Display output hotkey pressed. */
1889 acpi_bus_generate_proc_event(device
, event
, 0);
1890 keycode
= KEY_SWITCHVIDEOMODE
;
1892 case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT
: /* Next Display output hotkey pressed. */
1893 acpi_bus_generate_proc_event(device
, event
, 0);
1894 keycode
= KEY_VIDEO_NEXT
;
1896 case ACPI_VIDEO_NOTIFY_PREV_OUTPUT
: /* previous Display output hotkey pressed. */
1897 acpi_bus_generate_proc_event(device
, event
, 0);
1898 keycode
= KEY_VIDEO_PREV
;
1902 keycode
= KEY_UNKNOWN
;
1903 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1904 "Unsupported event [0x%x]\n", event
));
1908 acpi_notifier_call_chain(device
, event
, 0);
1909 input_report_key(input
, keycode
, 1);
1911 input_report_key(input
, keycode
, 0);
1917 static void acpi_video_device_notify(acpi_handle handle
, u32 event
, void *data
)
1919 struct acpi_video_device
*video_device
= data
;
1920 struct acpi_device
*device
= NULL
;
1921 struct acpi_video_bus
*bus
;
1922 struct input_dev
*input
;
1928 device
= video_device
->dev
;
1929 bus
= video_device
->video
;
1933 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS
: /* Cycle brightness */
1934 if (brightness_switch_enabled
)
1935 acpi_video_switch_brightness(video_device
, event
);
1936 acpi_bus_generate_proc_event(device
, event
, 0);
1937 keycode
= KEY_BRIGHTNESS_CYCLE
;
1939 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
: /* Increase brightness */
1940 if (brightness_switch_enabled
)
1941 acpi_video_switch_brightness(video_device
, event
);
1942 acpi_bus_generate_proc_event(device
, event
, 0);
1943 keycode
= KEY_BRIGHTNESSUP
;
1945 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
: /* Decrease brightness */
1946 if (brightness_switch_enabled
)
1947 acpi_video_switch_brightness(video_device
, event
);
1948 acpi_bus_generate_proc_event(device
, event
, 0);
1949 keycode
= KEY_BRIGHTNESSDOWN
;
1951 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS
: /* zero brightnesss */
1952 if (brightness_switch_enabled
)
1953 acpi_video_switch_brightness(video_device
, event
);
1954 acpi_bus_generate_proc_event(device
, event
, 0);
1955 keycode
= KEY_BRIGHTNESS_ZERO
;
1957 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF
: /* display device off */
1958 if (brightness_switch_enabled
)
1959 acpi_video_switch_brightness(video_device
, event
);
1960 acpi_bus_generate_proc_event(device
, event
, 0);
1961 keycode
= KEY_DISPLAY_OFF
;
1964 keycode
= KEY_UNKNOWN
;
1965 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
1966 "Unsupported event [0x%x]\n", event
));
1970 acpi_notifier_call_chain(device
, event
, 0);
1971 input_report_key(input
, keycode
, 1);
1973 input_report_key(input
, keycode
, 0);
1979 static int instance
;
1980 static int acpi_video_resume(struct acpi_device
*device
)
1982 struct acpi_video_bus
*video
;
1983 struct acpi_video_device
*video_device
;
1986 if (!device
|| !acpi_driver_data(device
))
1989 video
= acpi_driver_data(device
);
1991 for (i
= 0; i
< video
->attached_count
; i
++) {
1992 video_device
= video
->attached_array
[i
].bind_info
;
1993 if (video_device
&& video_device
->backlight
)
1994 acpi_video_set_brightness(video_device
->backlight
);
1999 static int acpi_video_bus_add(struct acpi_device
*device
)
2002 struct acpi_video_bus
*video
;
2003 struct input_dev
*input
;
2006 video
= kzalloc(sizeof(struct acpi_video_bus
), GFP_KERNEL
);
2010 /* a hack to fix the duplicate name "VID" problem on T61 */
2011 if (!strcmp(device
->pnp
.bus_id
, "VID")) {
2013 device
->pnp
.bus_id
[3] = '0' + instance
;
2016 /* a hack to fix the duplicate name "VGA" problem on Pa 3553 */
2017 if (!strcmp(device
->pnp
.bus_id
, "VGA")) {
2019 device
->pnp
.bus_id
[3] = '0' + instance
;
2023 video
->device
= device
;
2024 strcpy(acpi_device_name(device
), ACPI_VIDEO_BUS_NAME
);
2025 strcpy(acpi_device_class(device
), ACPI_VIDEO_CLASS
);
2026 device
->driver_data
= video
;
2028 acpi_video_bus_find_cap(video
);
2029 error
= acpi_video_bus_check(video
);
2031 goto err_free_video
;
2033 error
= acpi_video_bus_add_fs(device
);
2035 goto err_free_video
;
2037 mutex_init(&video
->device_list_lock
);
2038 INIT_LIST_HEAD(&video
->video_device_list
);
2040 acpi_video_bus_get_devices(video
, device
);
2041 acpi_video_bus_start_devices(video
);
2043 status
= acpi_install_notify_handler(device
->handle
,
2045 acpi_video_bus_notify
, video
);
2046 if (ACPI_FAILURE(status
)) {
2047 printk(KERN_ERR PREFIX
2048 "Error installing notify handler\n");
2050 goto err_stop_video
;
2053 video
->input
= input
= input_allocate_device();
2056 goto err_uninstall_notify
;
2059 snprintf(video
->phys
, sizeof(video
->phys
),
2060 "%s/video/input0", acpi_device_hid(video
->device
));
2062 input
->name
= acpi_device_name(video
->device
);
2063 input
->phys
= video
->phys
;
2064 input
->id
.bustype
= BUS_HOST
;
2065 input
->id
.product
= 0x06;
2066 input
->dev
.parent
= &device
->dev
;
2067 input
->evbit
[0] = BIT(EV_KEY
);
2068 set_bit(KEY_SWITCHVIDEOMODE
, input
->keybit
);
2069 set_bit(KEY_VIDEO_NEXT
, input
->keybit
);
2070 set_bit(KEY_VIDEO_PREV
, input
->keybit
);
2071 set_bit(KEY_BRIGHTNESS_CYCLE
, input
->keybit
);
2072 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
2073 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
2074 set_bit(KEY_BRIGHTNESS_ZERO
, input
->keybit
);
2075 set_bit(KEY_DISPLAY_OFF
, input
->keybit
);
2076 set_bit(KEY_UNKNOWN
, input
->keybit
);
2078 error
= input_register_device(input
);
2080 goto err_free_input_dev
;
2082 printk(KERN_INFO PREFIX
"%s [%s] (multi-head: %s rom: %s post: %s)\n",
2083 ACPI_VIDEO_DEVICE_NAME
, acpi_device_bid(device
),
2084 video
->flags
.multihead
? "yes" : "no",
2085 video
->flags
.rom
? "yes" : "no",
2086 video
->flags
.post
? "yes" : "no");
2091 input_free_device(input
);
2092 err_uninstall_notify
:
2093 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
2094 acpi_video_bus_notify
);
2096 acpi_video_bus_stop_devices(video
);
2097 acpi_video_bus_put_devices(video
);
2098 kfree(video
->attached_array
);
2099 acpi_video_bus_remove_fs(device
);
2102 device
->driver_data
= NULL
;
2107 static int acpi_video_bus_remove(struct acpi_device
*device
, int type
)
2109 acpi_status status
= 0;
2110 struct acpi_video_bus
*video
= NULL
;
2113 if (!device
|| !acpi_driver_data(device
))
2116 video
= acpi_driver_data(device
);
2118 acpi_video_bus_stop_devices(video
);
2120 status
= acpi_remove_notify_handler(video
->device
->handle
,
2122 acpi_video_bus_notify
);
2124 acpi_video_bus_put_devices(video
);
2125 acpi_video_bus_remove_fs(device
);
2127 input_unregister_device(video
->input
);
2128 kfree(video
->attached_array
);
2134 static int __init
acpi_video_init(void)
2138 acpi_video_dir
= proc_mkdir(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2139 if (!acpi_video_dir
)
2141 acpi_video_dir
->owner
= THIS_MODULE
;
2143 result
= acpi_bus_register_driver(&acpi_video_bus
);
2145 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2152 static void __exit
acpi_video_exit(void)
2155 acpi_bus_unregister_driver(&acpi_video_bus
);
2157 remove_proc_entry(ACPI_VIDEO_CLASS
, acpi_root_dir
);
2162 module_init(acpi_video_init
);
2163 module_exit(acpi_video_exit
);