#### AUTHOR miura@da-cha.org #### COMMENT START ### Comments for ChangeSet [ACPI] add acpi_video driver. It support LCD/VGA switch on some laptop note. This implements part of the ACPI spec 2.0c Appendix B features. Signed-off-by: Hiroshi Miura ### Comments for include/acpi/acpi_bus.h [ACPI] add acpi_video driver. ### Comments for drivers/acpi/video.c ### Comments for drivers/acpi/video.c BitKeeper file /home/miura/kernel/linux-2.6.9-rc1-hm/drivers/acpi/video.c ### Comments for drivers/acpi/scan.c [ACPI] add acpi_video driver. ### Comments for drivers/acpi/Makefile [ACPI] add acpi_video driver. ### Comments for drivers/acpi/Kconfig [ACPI] add acpi_video driver. #### COMMENT END # This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2004/09/22 08:14:05+09:00 miura@da-cha.org # [ACPI] add acpi_video driver. It support LCD/VGA switch on some laptop note. # This implements part of the ACPI spec 2.0c Appendix B features. # # Signed-off-by: Hiroshi Miura # # drivers/acpi/video.c # 2004/09/22 08:13:44+09:00 miura@da-cha.org +1098 -0 # # include/acpi/acpi_bus.h # 2004/09/22 08:13:44+09:00 miura@da-cha.org +2 -0 # [ACPI] add acpi_video driver. # # drivers/acpi/video.c # 2004/09/22 08:13:44+09:00 miura@da-cha.org +0 -0 # BitKeeper file /home/miura/kernel/linux-2.6.9-rc1-hm/drivers/acpi/video.c # # drivers/acpi/scan.c # 2004/09/22 08:13:44+09:00 miura@da-cha.org +8 -1 # [ACPI] add acpi_video driver. # # drivers/acpi/Makefile # 2004/09/22 08:13:44+09:00 miura@da-cha.org +1 -0 # [ACPI] add acpi_video driver. # # drivers/acpi/Kconfig # 2004/09/22 08:13:44+09:00 miura@da-cha.org +10 -0 # [ACPI] add acpi_video driver. # diff -Nru a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig --- a/drivers/acpi/Kconfig 2004-09-22 09:11:11 +09:00 +++ b/drivers/acpi/Kconfig 2004-09-22 09:11:11 +09:00 @@ -139,6 +139,16 @@ recommended that this option be enabled, as your processor(s) may be damaged without it. +config ACPI_VIDEO + tristate "Video extension" + depends on ACPI_INTERPRETER + default m + help + This Driver adds support for ACPI video extension. Most recent + mobile systems support ACPI video extension. You can control + CRT/LCD output switch and LCD brightness through ACPI. + Now this driver is experimental. + config ACPI_NUMA bool "NUMA support" depends on ACPI_INTERPRETER diff -Nru a/drivers/acpi/Makefile b/drivers/acpi/Makefile --- a/drivers/acpi/Makefile 2004-09-22 09:11:11 +09:00 +++ b/drivers/acpi/Makefile 2004-09-22 09:11:11 +09:00 @@ -49,3 +49,4 @@ obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_ACPI_PCC) += pcc_acpi.o obj-$(CONFIG_ACPI_BUS) += scan.o motherboard.o +obj-$(CONFIG_ACPI_VIDEO) += video.o diff -Nru a/drivers/acpi/scan.c b/drivers/acpi/scan.c --- a/drivers/acpi/scan.c 2004-09-22 09:11:11 +09:00 +++ b/drivers/acpi/scan.c 2004-09-22 09:11:11 +09:00 @@ -312,7 +312,14 @@ struct acpi_device *device, struct acpi_driver *driver) { - return acpi_match_ids(device, driver->ids); + int error = 0; + + if (driver->ops.match) { + error = driver->ops.match(device, driver); + } else { + error = acpi_match_ids(device, driver->ids); + } + return error; } diff -Nru a/drivers/acpi/video.c b/drivers/acpi/video.c --- /dev/null Wed Dec 31 16:00:00 196900 +++ b/drivers/acpi/video.c 2004-09-22 09:11:11 +09:00 @@ -0,0 +1,1098 @@ +/* + * ACPI Video Extentions driver + * (C) 2004 Hiroshi Miura + * (C) 2004 Bruno Ducrot + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * publicshed by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * This driver implements ACPIspec 2.0c Appendix. B VIDEO EXTENSIONS + * + *--------------------------------------------------------------------------- + * + * ChangeLog: + * Sep.20, 2004 Hiroshi Miura + * - v0.6 merge Ducrot's code. + * + * Jul.20, 2004 Hiroshi Miura + * - v0.2 implement BCM,BCL lcd brightness methods + * - add PSx methods + * + * Jul.17, 2004 Hiroshi Miura + * - v0.1 remove static definition of path. + * + * Jul.10, 2004 Hiroshi Miura + * - v0.02 add _DSS method and lcd/crt path. + * + * Jul. 9, 2004 Hiroshi Miura + * - v0.01 _DOS method + * + */ + +#define ACPI_VIDEO_EXT_VERSION "0.6" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define ACPI_VIDEO_COMPONENT 0x08000000 +#define ACPI_VIDEO_DRIVER_NAME "ACPI Video Driver" +#define ACPI_VIDEO_CLASS "video" +#define ACPI_VIDEO_DEVICE_NAME "Video Device" +#define ACPI_VIDEO_NOTIFY_STATUS 0x80 +#define ACPI_VIDEO_NOTIFY_INFO 0x81 + +#define _COMPONENT ACPI_VIDEO_COMPONENT +ACPI_MODULE_NAME ("video") + +MODULE_AUTHOR("Hiroshi Miura"); +MODULE_DESCRIPTION(ACPI_VIDEO_DRIVER_NAME); +MODULE_LICENSE("GPL"); + +#define LOGPREFIX "acpi_video: " + +/**************************************************** + * ACPI Video ext. standard methods + ****************************************************/ + +/* + * video output control + */ +#define METHOD_OUTDEV_SWITCH "_DOS" +#define METHOD_OUTDEV_QUERY "_DOD" + +/* display change via hotkey */ +#define METHOD_VID_STAT "_DCS" +#define METHOD_VID_QUERY "_DGS" +#define METHOD_VID_SET "_DSS" + +/* defined values for _DOS method */ +#define DOS_GEN_DISPLAY_EVENT 0 +#define DOS_AUTO_DISPLAY_SW 1 +#define DOS_LOCK_DISPLAY_SW 2 +#define DOS_BRIGHT_AUTO_SW (0 << 2) +#define DOS_BRIGHT_NOT_SW (1 << 2) + +#define DOD_MONITOR 0x0100 +#define DOD_PANEL 0x0110 +#define DOD_TV 0x0200 + +/* defined values for _DCS method + * bit + * 0 Output connector exists in the system now + * 1 Output is activated + * 2 Output is ready to switch + * 3 Output is not defective (it is functioning properly) + * 4 Device is attached (this is optional) + * ex.) + * If the output signal is activated by _DSS, _DCS returns 0x1F or 0x0F. + * If the output signal is inactivated by _DSS, _DCS returns 0x1D or 0x0D. + * If the device is not attached or cannot be detected, + * _DCS returns 0x0xxxx and should return 0x1xxxx if it is attached. + * If the output signal cannot be activated, _ DCS returns 0x1B or 0x0B. + * If the output connector does not exist (when undocked), _DCS returns 0x00. + */ +#define DCS_EXIST 1 +#define DCS_ACTIVATED (1 << 1) +#define DCS_READY_TO_SW (1 << 2) +#define DCS_NO_DEFECTIVE (1 << 3) +#define DCS_DEV_ATTACH (1 << 4) + +/* DGS 1 next on, 0 next off */ + +/* defined values for _DSS method + * bit 0 + * 0 = Set output device to inactive state + * 1 = Set output device to active state + * bit 30 + * 0 = Do whatever Bit31 requires to do + * 1 = Don t do actual switching, but need to change _DGS to next state + * bit 31 + * 0 = Don t do actual switching, just cache the change + * 1 = If Bit30=0, commit actual switching, including any _DSS with MSB=0 + * called before + * If Bit30=1, don t do actual switching, change _DGS to next state + * OS may call in such an order to turn off CRT, and turn on LCD + * CRT._DSS(0); + * LCD._DSS(80000001L); + * or + * LCD._DSS(1); + * CRT._DSS(80000000L); + * OS may call in such an order to force BIOS to make _DGS jump to next state without actual CRT, LCD switching + * CRT._DSS(40000000L); + * LCD._DSS(C0000001L); + */ +#define DSS_ACTIVATE 1 +#define DSS_QUEUE_NEXT (1 << 30) +#define DSS_COMMIT_CHG (1 << 31) + +/* LCD Brightness methods */ + +#define METHOD_BRIGHTNESS_QUERY "_BCL" +#define METHOD_BRIGHTNESS_SET "_BCM" + +/******************************************************************* + * + * definitions for /proc/ interface + * + *******************************************************************/ + +#define ACPI_VIDEO_HEAD_INVALID (~0ul - 1) +#define ACPI_VIDEO_HEAD_END (~0ul) + +static int acpi_video_bus_add (struct acpi_device *device); +static int acpi_video_bus_remove (struct acpi_device *device, int type); +static int acpi_video_bus_match (struct acpi_device *device, struct acpi_driver *driver); + +static struct acpi_driver acpi_video_driver = { + .name = ACPI_VIDEO_DRIVER_NAME, + .class = ACPI_VIDEO_CLASS, + .ids = NULL, + .ops = { + .add = acpi_video_bus_add, + .remove = acpi_video_bus_remove, + .match = acpi_video_bus_match, + }, +}; + +struct acpi_video_bus_flags { + u8 multihead:1; /* can switch video heads */ + u8 rom:1; /* can retrieve a video rom */ + u8 post:1; /* can configure the head to + * be POSTed at boot */ + u8 reserved:5; +}; + +struct acpi_video_bus { + acpi_handle handle; + unsigned long *device_ids; + struct acpi_video_bus_flags flags; + struct semaphore sem; + struct list_head video_driver_list; +}; + +struct acpi_video_device { + acpi_handle handle; + unsigned long device_id; + struct list_head entry; + struct acpi_video_bus *video; + struct acpi_device *device; + unsigned long status; +}; + +struct proc_dir_entry *acpi_video_dir; + +static int acpi_video_device_info_open_fs(struct inode *, struct file *); +static int acpi_video_device_state_open_fs(struct inode *, struct file *); +static int acpi_video_device_power_open_fs(struct inode *, struct file *); +static int acpi_video_lcd_brightness_open_fs(struct inode *, struct file *); +static int acpi_video_lcd_brightness_list_open_fs(struct inode *, struct file *); +static int acpi_video_version_open_fs(struct inode *, struct file *); +static ssize_t acpi_video_device_write_state (struct file*, const char __user *,size_t,loff_t *); +static ssize_t acpi_video_write_psx (struct file*, const char __user *,size_t,loff_t *); +static ssize_t acpi_video_write_lcd_brightness (struct file*, const char __user *,size_t,loff_t *); + +static struct file_operations acpi_video_device_info_fops = { + .open = acpi_video_device_info_open_fs, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static struct file_operations acpi_video_device_state_fops = { + .open = acpi_video_device_state_open_fs, + .read = seq_read, + .write = acpi_video_device_write_state, + .llseek = seq_lseek, + .release = single_release, +}; +static struct file_operations acpi_video_device_power_fops = { + .open = acpi_video_device_power_open_fs, + .read = seq_read, + .write = acpi_video_write_psx, + .llseek = seq_lseek, + .release = single_release, +}; +static struct file_operations acpi_video_lcd_brightness_fops = { + .open = acpi_video_lcd_brightness_open_fs, + .read = seq_read, + .write = acpi_video_write_lcd_brightness, + .llseek = seq_lseek, + .release = single_release, +}; +static struct file_operations acpi_video_lcd_brightness_list_fops = { + .open = acpi_video_lcd_brightness_list_open_fs, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static struct file_operations acpi_video_version_fops = { + .open = acpi_video_version_open_fs, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int acpi_video_do_psx(struct acpi_video_device *video, int value) +{ + acpi_status status = AE_OK; + + switch (value) { + case 0: + status = acpi_evaluate_object(video->handle, "_PS0", NULL, NULL); + break; + case 1: + status = acpi_evaluate_object(video->handle, "_PS1", NULL, NULL); + break; + case 2: + status = acpi_evaluate_object(video->handle, "_PS2", NULL, NULL); + break; + case 3: + status = acpi_evaluate_object(video->handle, "_PS3", NULL, NULL); + break; + default: + break; + } + + if (ACPI_FAILURE(status)) { + return (-EFAULT); + } + + return (status == AE_OK); +} + +/* + * proc file handlers + */ +static int acpi_video_bus_ownership (struct acpi_video_bus *video, int get) +{ + acpi_integer status; + union acpi_object arg0 = {ACPI_TYPE_INTEGER}; + struct acpi_object_list args = {1, &arg0}; + + ACPI_FUNCTION_TRACE("acpi_video_bus_ownership"); + + arg0.integer.value = get; + + status = acpi_evaluate_object(video->handle, METHOD_OUTDEV_SWITCH, &args, NULL); + + return_VALUE(status); +} + +static acpi_status acpi_video_device_get_state (struct acpi_video_device *device, unsigned long *state) +{ + acpi_status status; + + ACPI_FUNCTION_TRACE("acpi_video_device_get_state"); + + status = acpi_evaluate_integer(device->handle, "_DCS", NULL, state); + + return_VALUE(status); +} + +static acpi_status acpi_video_device_query (struct acpi_video_device *device, unsigned long *state) +{ + acpi_status status; + + ACPI_FUNCTION_TRACE("acpi_video_device_query"); + + status = acpi_evaluate_integer(device->handle, "_DGS", NULL, state); + + return_VALUE(status); +} + +static int acpi_video_do_write_state(struct acpi_video_device *video, unsigned long value) +{ + acpi_status status=AE_OK; + union acpi_object arg0 = {ACPI_TYPE_INTEGER}; + struct acpi_object_list args = {1, &arg0}; + + ACPI_FUNCTION_TRACE("acpi_video_do_write_state"); + + arg0.integer.value = value; + + status = acpi_evaluate_object(video->handle, "_DSS", &args, NULL); + + return_VALUE(status == AE_OK); +} + +static ssize_t acpi_video_device_write_state(struct file *file, const char __user *buffer, size_t count, loff_t *data) +{ + struct seq_file *seq = (struct seq_file *) file->private_data; + struct acpi_video_device *device = (struct acpi_video_device *) seq->private; + char str[12] = {0}; + unsigned long value; + + ACPI_FUNCTION_TRACE("acpi_video_device_write_state"); + + if (!device || count + 1 > sizeof(str)) + return_VALUE(-EINVAL); + + if (copy_from_user(str, buffer, count)) + return_VALUE(-EFAULT); + + str[count] = '\0'; + + if (sscanf(str, "%lu", &value) == 1) { + value = value & (DSS_ACTIVATE | DSS_QUEUE_NEXT | DSS_COMMIT_CHG); + if (!acpi_video_do_write_state(device, value)) + return_VALUE(-EFAULT); + } + + return_VALUE(count); +} + +static ssize_t acpi_video_write_psx(struct file *file, const char __user *buffer, size_t count, loff_t *data) +{ + struct seq_file *seq = (struct seq_file *) file->private_data; + struct acpi_video_device *device = (struct acpi_video_device *) seq->private; + char str[12] = {0}; + int value; + + ACPI_FUNCTION_TRACE("acpi_video_write_psx"); + + if (!device || count + 1 > sizeof(str)) + return_VALUE(-EINVAL); + + if (copy_from_user(str, buffer, count)) + return_VALUE(-EFAULT); + + str[count] = '\0'; + + if (sscanf(str, "%i", &value) == 1 && value >= 0 && value < 4) + if (!acpi_video_do_psx(device, value)) + return_VALUE(-EFAULT); + + return_VALUE(count); +} +static int acpi_video_device_power_show(struct seq_file *seq, void *offset) +{ + ACPI_FUNCTION_TRACE("acpi_video_device_power_show"); + + return_VALUE(0); +} +static int acpi_video_device_power_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_video_device_power_show, PDE(inode)->data); +} + + +static ssize_t acpi_video_device_info_show (struct seq_file *seq, void *offset) +{ + struct acpi_video_device *video_dev = (struct acpi_video_device *) seq->private; + + ACPI_FUNCTION_TRACE("acpi_video_device_info_show"); + + if (!video_dev) + return_VALUE(0); + + seq_printf(seq, "device_id: 0x%04x\n", (u32) video_dev->device_id); + seq_printf(seq, "type: "); + +#define DEVICE_CRT 0x0100 +#define DEVICE_LCD 0x0110 +#define DEVICE_TVOUT 0x0200 +#define DEVICE_DFP 0x0400 + + switch (video_dev->device_id) { + case DEVICE_CRT: + seq_printf(seq, "CRT\n"); + break; + case DEVICE_LCD: + seq_printf(seq, "LCD\n"); + break; + case DEVICE_TVOUT: + seq_printf(seq, "TVOUT\n"); + break; + case DEVICE_DFP: + seq_printf(seq, "DFP\n"); + break; + default: + seq_printf(seq, "UNKNOWN\n"); + } + + return_VALUE(0); +} +static int acpi_video_device_info_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_video_device_info_show, PDE(inode)->data); +} + + + +static ssize_t acpi_video_device_state_show (struct seq_file *seq, void *offset) +{ + struct acpi_video_device *dev = (struct acpi_video_device *) seq->private; + acpi_status status=AE_OK; + unsigned long state; + + + ACPI_FUNCTION_TRACE("acpi_video_device_state_show"); + + if (!dev) + return_VALUE(0); + + status = acpi_video_device_get_state(dev, &state); + seq_printf(seq, "state: "); + if (ACPI_SUCCESS(status)) + seq_printf(seq, "0x%02lx\n", state); + else + seq_printf(seq, "\n"); + + status = acpi_video_device_query(dev, &state); + seq_printf(seq, "query: "); + if (ACPI_SUCCESS(status)) + seq_printf(seq, "0x%02lx\n", state); + else + seq_printf(seq, "\n"); + + return_VALUE(0); +} + +static int acpi_video_device_state_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_video_device_state_show, PDE(inode)->data); +} + +static int* brightness; + +static int retrive_brightness_list(struct acpi_video_device* device) +{ + acpi_status status = AE_OK; + struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; + union acpi_object *bcl = NULL; + int i; + + if (brightness) + return 0; + + status = acpi_evaluate_object(device->handle, METHOD_BRIGHTNESS_QUERY, 0, &buffer); + if(ACPI_FAILURE(status)) { + printk(KERN_INFO LOGPREFIX "Error evaluating _BCL\n"); + return (status == AE_OK); + } + bcl = (union acpi_object *) buffer.pointer; + if (!bcl || (bcl->type != ACPI_TYPE_PACKAGE)) { + printk(KERN_INFO LOGPREFIX "Invalid _BCL data\n"); + status = AE_ERROR; + goto end; + } + + if ((brightness = (int*)kmalloc(sizeof(int) * (bcl->package.count + 1), GFP_KERNEL)) == NULL ) { + status = AE_ERROR; + goto end; + } + + for (i = 0; i < bcl->package.count; i++) { + union acpi_object *element = &(bcl->package.elements[i]); + if (likely(element->type == ACPI_TYPE_INTEGER)) { + brightness[i] = (int)element->integer.value; + } else + printk(KERN_INFO LOGPREFIX "Invalid _BCL data\n"); + } + brightness[bcl->package.count] = -1; + +end: + acpi_os_free(buffer.pointer); + return (status == AE_OK); +} + +static int acpi_video_do_bcm(struct acpi_video_device* device, unsigned long value) +{ + int i; + acpi_status status; + + if (!brightness && !retrive_brightness_list(device)) + return 0; + + for (i = 0; brightness[i] >= 0 && brightness[i] == value; i++); + if (brightness[i] < 0) { + printk(KERN_INFO "passed lcd brightness value is invalid.\n"); + return 0; + } + + status = acpi_evaluate_integer(device->handle, METHOD_BRIGHTNESS_SET, NULL, &value); + + return (status == AE_OK); +} + +static ssize_t acpi_video_lcd_brightness_show (struct seq_file *seq, void *offset) +{ + return 0; +} + +static ssize_t acpi_video_write_lcd_brightness(struct file *file, const char __user *buffer, size_t count, loff_t *data) +{ + struct seq_file *seq = (struct seq_file *) file->private_data; + struct acpi_video_device *device = (struct acpi_video_device *) seq->private; + char str[12] = {0}; + int value; + + ACPI_FUNCTION_TRACE("acpi_video_write_lcd_brightness"); + + if (!device || count + 1 > sizeof(str)) + return_VALUE(-EINVAL); + + if (copy_from_user(str, buffer, count)) + return_VALUE(-EFAULT); + + str[count] = '\0'; + + if (sscanf(buffer, "%i", &value) == 1 && value >= 0 && value <= 100) + if (!acpi_video_do_bcm(device, (unsigned long) value)) + return -EFAULT; + + return count; +} + +static int acpi_video_lcd_brightness_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_video_lcd_brightness_show, PDE(inode)->data); +} + +static ssize_t acpi_video_lcd_brightness_list_show (struct seq_file *seq, void *offset) +{ + struct acpi_video_device *dev = (struct acpi_video_device *) seq->private; + int i; + + if (!retrive_brightness_list(dev)) + return 0; + + for (i = 0; brightness[i] >= 0 ; i++) { + seq_printf(seq, "%d", brightness[i]); + + switch (i) { + case 0: + seq_printf(seq, "(max),"); + break; + case 1: + seq_printf(seq, "(min),"); + break; + default: + seq_printf(seq, ","); + } + } + + return 0; +} + +static int acpi_video_lcd_brightness_list_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_video_lcd_brightness_list_show, PDE(inode)->data); +} + +static int acpi_video_version_show(struct seq_file *seq, void *offset) +{ + ACPI_FUNCTION_TRACE("acpi_video_version_show"); + + seq_printf(seq, "driver: %s\n", ACPI_VIDEO_EXT_VERSION); + + return_VALUE(0); +} +static int acpi_video_version_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_video_version_show, PDE(inode)->data); +} + +void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data) +{ + struct acpi_video_bus *video = (struct acpi_video_bus *) data; + acpi_status status; + struct list_head *node, *next; + unsigned long state, report = 0; + struct acpi_device *device = NULL; + + ACPI_FUNCTION_TRACE("acpi_video_bus_nofity"); + + if (!video) + return_VOID; + + if (acpi_bus_get_device(handle, &device)) + return_VOID; + + switch(event) { + case ACPI_VIDEO_NOTIFY_STATUS: + list_for_each_safe(node, next, &video->video_driver_list) { + struct acpi_video_device *vid_dev = list_entry(node, struct acpi_video_device, entry); + if (!vid_dev) + continue; + status = acpi_video_device_query(vid_dev, &state); + if (ACPI_FAILURE(status)) + printk(KERN_WARNING PREFIX "bug in acpi video driver.\n"); + report = (report << 16) | (vid_dev->device_id & 0x0ff0) | (state & 0x01); + } + acpi_bus_generate_event(device, event, report); + break; + case ACPI_VIDEO_NOTIFY_INFO: + acpi_bus_generate_event(device, event, 0); + break; + default: + break; + } + + return; +} + + +typedef struct _ProcItem +{ + const char* name; + struct file_operations *fops; + mode_t flag; + char *method; +} ProcItem; + +ProcItem video_proc_items[] = +{ + { "version", &acpi_video_version_fops, S_IRUGO, NULL}, + { "power" , &acpi_video_device_power_fops, S_IFREG | S_IRUGO | S_IWUSR, "_PS0" }, + { NULL , NULL , 0 , NULL}, +}; + +ProcItem video_device_proc_items[] = +{ + { "info" , &acpi_video_device_info_fops, S_IRUGO, NULL }, + { "state" , &acpi_video_device_state_fops, S_IFREG | S_IRUGO | S_IWUSR, NULL }, + + { "brightness" , &acpi_video_lcd_brightness_fops, S_IFREG | S_IRUGO | S_IWUSR, METHOD_BRIGHTNESS_SET }, + { "brightness_list" , &acpi_video_lcd_brightness_list_fops, S_IRUGO, METHOD_BRIGHTNESS_QUERY }, + { "power" , &acpi_video_device_power_fops, S_IFREG | S_IRUGO | S_IWUSR, "_PS0" }, + { NULL , NULL , 0 , NULL}, +}; + + +static int acpi_video_method_check(acpi_handle *handle, char *method) +{ + int status=-ENOENT; + + acpi_handle h_dummy; + + ACPI_FUNCTION_TRACE("acpi_video_method_check"); + + if (!handle) + return_VALUE(-EINVAL); + + if (!method) + return_VALUE(-EINVAL); + + if (ACPI_SUCCESS(acpi_get_handle(handle, method, &h_dummy))) + status = 0; + + return_VALUE(status); +} + +static int __init acpi_video_device_add_entry(ProcItem *proc_items, struct acpi_device *device) +{ + struct proc_dir_entry* proc; + ProcItem* item; + int i; + acpi_status status; + struct acpi_video_device *video_device = (struct acpi_video_device *)acpi_driver_data(device); + + for (item = proc_items, i = 0; item->name; ++item, i++) { + if (item->method) { + status = acpi_video_method_check(video_device->handle, item->method); + if (ACPI_FAILURE(status)) + continue; + } + + proc = create_proc_entry(item->name, item->flag, acpi_device_dir(device)); + if (likely(proc)) { + proc->proc_fops = item->fops; + proc->data = acpi_driver_data(device); + proc->owner = THIS_MODULE; + } else { + return -ENODEV; + } + } + + return 0; +} + +static int acpi_video_device_add_fs (struct acpi_device *device) +{ + struct acpi_video_device *video_dev; + + ACPI_FUNCTION_TRACE("acpi_video_device_add_fs"); + + if (!device) + return_VALUE(-ENODEV); + + video_dev = (struct acpi_video_device *) acpi_driver_data(device); + if (!video_dev) + return_VALUE(-ENODEV); + + if (!acpi_device_dir(device)) { + acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), acpi_video_dir); + if (!acpi_device_dir(device)) + return_VALUE(-ENODEV); + } + + acpi_video_device_add_entry(video_device_proc_items, device); + + return_VALUE(0); +} + +static int acpi_video_bus_get_one_device (struct acpi_device *device, struct acpi_video_bus *video) +{ + unsigned long device_id; + int status; + struct acpi_video_device *vid_dev; + + ACPI_FUNCTION_TRACE("acpi_video_bus_get_one_device"); + + if (!device || !video) + return_VALUE(-EINVAL); + + status = acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); + if (ACPI_SUCCESS(status)) { + vid_dev = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL); + if (!vid_dev) + return_VALUE(-ENOMEM); + + memset(vid_dev, 0, sizeof(struct acpi_video_device)); + + vid_dev->handle = device->handle; + strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); + strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); + acpi_driver_data(device) = vid_dev; + + vid_dev->device_id = device_id; + vid_dev->video = video; + vid_dev->device = device; + + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found device_id: 0x%04x \n", (u32) device_id)); + + down(&video->sem); + list_add_tail(&vid_dev->entry, &video->video_driver_list); + up(&video->sem); + + acpi_video_device_add_fs(device); + + return_VALUE(0); + } else { + printk(KERN_WARNING PREFIX "cannot get.\n"); + } + + return_VALUE(-ENOENT); +} + +static int acpi_video_bus_get_devices (struct acpi_video_bus *video, struct acpi_device *device) +{ + int status; + int count; + int i; + unsigned long *device_ids; + struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; + union acpi_object *dod = NULL; + union acpi_object *obj; + struct list_head *node, *next; + + ACPI_FUNCTION_TRACE("acpi_video_get_devices"); + + status = acpi_evaluate_object(video->handle, "_DOD", NULL, &buffer); + if (!ACPI_SUCCESS(status)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _DOD\n")); + return_VALUE(status); + } + + dod = (union acpi_object *) buffer.pointer; + if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _DOD data\n")); + status = -EFAULT; + goto out; + } + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d video heads in _DOD\n", + dod->package.count)); + + device_ids = kmalloc(dod->package.count * sizeof(device_ids[0]), GFP_KERNEL); + if (!device_ids) { + status = -ENOMEM; + goto out; + } + + count = 0; + for (i = 0; i < dod->package.count; i++) { + obj = (union acpi_object *) &dod->package.elements[i]; + + if (obj->type != ACPI_TYPE_INTEGER) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _DOD data\n")); + device_ids[i] = ACPI_VIDEO_HEAD_INVALID; + } + + device_ids[i] = obj->integer.value; + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found device_id: 0x%08x \n", (u32) device_ids[i])); + count++; + } + device_ids[count] = ACPI_VIDEO_HEAD_END; + video->device_ids = device_ids; + + list_for_each_safe(node, next, &device->children) { + struct acpi_device *dev = list_entry(node, struct acpi_device, node); + + if (!dev) + continue; + + status = acpi_video_bus_get_one_device(dev, video); + if (ACPI_FAILURE(status)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Cant attach device\n")); + continue; + } + } + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found valid %d video heads\n", count)); + +out: + acpi_os_free(buffer.pointer); + return_VALUE(status); +} + +static int acpi_video_device_remove_fs (struct acpi_device *device) +{ + struct acpi_video_device *video_dev = (struct acpi_video_device *) acpi_driver_data(device); + ACPI_FUNCTION_TRACE("acpi_video_device_remove_fs"); + + if (!video_dev) + return_VALUE(-ENODEV); + + if (acpi_device_dir(device)) { + remove_proc_entry(acpi_device_bid(device), acpi_device_dir(device)); + acpi_device_dir(device) = NULL; + } + + return_VALUE(0); +} + +static int acpi_video_bus_put_one_device(struct acpi_video_device *video_device) +{ + struct acpi_video_bus *video; + + ACPI_FUNCTION_TRACE("acpi_video_bus_put_one_device"); + + if (!video_device || !video_device->video) + return (-ENOENT); + + video = video_device->video; + + down(&video->sem); + list_del(&video_device->entry); + up(&video->sem); + + acpi_video_device_remove_fs(video_device->device); + + return_VALUE(0); +} + +static int acpi_video_bus_put_devices (struct acpi_video_bus *video) +{ + int status; + struct list_head *node, *next; + + ACPI_FUNCTION_TRACE("acpi_video_bus_put_devices"); + + list_for_each_safe(node, next, &video->video_driver_list) { + struct acpi_video_device *data = list_entry(node, struct acpi_video_device, entry); + if (!data) + continue; + + status = acpi_video_bus_put_one_device(data); + if(ACPI_FAILURE(status)) + printk(KERN_WARNING PREFIX "hhuuhhuu bug in acpi video driver.\n"); + + kfree(data); + } + + return_VALUE(0); +} + +static int __init acpi_video_bus_add_entry(ProcItem *proc_items, struct acpi_device *device) +{ + struct proc_dir_entry* proc; + ProcItem* item; + int i; + struct acpi_video_bus *video = (struct acpi_video_bus *) acpi_driver_data(device); + + for (item = proc_items, i = 0; item->name; ++item, i++) { + if (item->method) { + if (acpi_video_method_check(device->handle, item->method)) + continue; + } + + proc = create_proc_entry(item->name, item->flag, acpi_device_dir(device)); + if (likely(proc)) { + proc->proc_fops = item->fops; + proc->data = video; + proc->owner = THIS_MODULE; + } else { + return -ENODEV; + } + } + return 0; +} + +static int acpi_video_bus_add_fs (struct acpi_device *device) +{ + ACPI_FUNCTION_TRACE("acpi_video_bus_add_fs"); + + if (!acpi_device_dir(device)) { + acpi_device_dir(device) = proc_mkdir(ACPI_VIDEO_CLASS, acpi_root_dir); + if (!acpi_device_dir(device)) + return_VALUE(-ENODEV); + } + acpi_video_dir = acpi_device_dir(device); + acpi_video_bus_add_entry(video_proc_items, device); + + return_VALUE(0); +} + +static int acpi_video_bus_remove_fs (struct acpi_device *device) +{ + ACPI_FUNCTION_TRACE("acpi_video_bus_remove_fs"); + + if (acpi_device_dir(device)) { + remove_proc_entry(acpi_device_bid(device), acpi_video_dir); + acpi_device_dir(device) = NULL; + } + + return_VALUE(0); +} + +static int acpi_video_bus_add (struct acpi_device *device) +{ + int result = 0; + acpi_status status = AE_OK; + struct acpi_video_bus *video = NULL; + + ACPI_FUNCTION_TRACE("acpi_video_bus_add"); + + if (!device) + return_VALUE(-EINVAL); + + video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); + if (!video) + return_VALUE(-ENOMEM); + + memset(video, 0, sizeof(struct acpi_video_bus)); + + video->handle = device->handle; + acpi_driver_data(device) = video; + strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); + strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); + + result = acpi_video_bus_add_fs(device); + + if (result) + goto end; + + init_MUTEX(&video->sem); + INIT_LIST_HEAD(&video->video_driver_list); + + acpi_video_bus_get_devices(video, device); + + acpi_video_bus_ownership(video, DOS_GEN_DISPLAY_EVENT | DOS_BRIGHT_NOT_SW ); + + status = acpi_install_notify_handler (video->handle, + ACPI_DEVICE_NOTIFY, acpi_video_bus_notify, video); + + if (ACPI_FAILURE(status)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error installing notify handler\n")); + kfree(video); + goto end; + } + +end: + if (result) { + acpi_video_bus_remove_fs(device); + kfree(video); + } + + return_VALUE(result); +} + +static int acpi_video_bus_remove(struct acpi_device *device, int type) +{ + acpi_status status = 0; + struct acpi_video_bus *video = (struct acpi_video_bus *) acpi_driver_data(device); + + ACPI_FUNCTION_TRACE("acpi_video_bus_remove"); + + if (!device || !video) + return_VALUE(-EINVAL); + + acpi_video_bus_ownership(video, DOS_AUTO_DISPLAY_SW | DOS_BRIGHT_AUTO_SW); + + status = acpi_remove_notify_handler(video->handle, + ACPI_DEVICE_NOTIFY, acpi_video_bus_notify); + if (ACPI_FAILURE(status)) + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error removing notify handler\n")); + + acpi_video_bus_put_devices(video); + acpi_video_bus_remove_fs(device); + + kfree(video); + return_VALUE(0); +} + +static int acpi_video_bus_match (struct acpi_device *device, struct acpi_driver *driver) +{ + acpi_handle h_dummy1; + acpi_handle h_dummy2; + + ACPI_FUNCTION_TRACE("acpi_video_bus_match"); + + if (!device || !driver) + return_VALUE(-EINVAL); + + /* Since there is no HID, CID for ACPI Video drivers, we have + * to check well known required nodes for each feature we support. + */ + + /* Does this device able to support video switching ? */ + if (ACPI_SUCCESS(acpi_get_handle(device->handle, METHOD_OUTDEV_QUERY, &h_dummy1)) && + ACPI_SUCCESS(acpi_get_handle(device->handle, METHOD_OUTDEV_SWITCH, &h_dummy2))) + return_VALUE(0); + + return_VALUE(-ENODEV); +} + +static int __init acpi_video_init(void) +{ + acpi_status result; + + ACPI_FUNCTION_TRACE("acpi_video_init"); + + result = acpi_bus_register_driver(&acpi_video_driver); + if (result < 0) + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error registering video driver\n")); + + return_VALUE(result); +} + +static void __exit acpi_video_exit(void) +{ + ACPI_FUNCTION_TRACE("acpi_video_exit"); + + acpi_bus_unregister_driver(&acpi_video_driver); + + return_VOID; +} + +module_init(acpi_video_init); +module_exit(acpi_video_exit); diff -Nru a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h --- a/include/acpi/acpi_bus.h 2004-09-22 09:11:11 +09:00 +++ b/include/acpi/acpi_bus.h 2004-09-22 09:11:11 +09:00 @@ -104,6 +104,7 @@ typedef int (*acpi_op_resume) (struct acpi_device *device, int state); typedef int (*acpi_op_scan) (struct acpi_device *device); typedef int (*acpi_op_bind) (struct acpi_device *device); +typedef int (*acpi_op_match) (struct acpi_device *device, struct acpi_driver *driver); struct acpi_device_ops { acpi_op_add add; @@ -115,6 +116,7 @@ acpi_op_resume resume; acpi_op_scan scan; acpi_op_bind bind; + acpi_op_match match; }; struct acpi_driver {