From a1f0eff21edac1bd87e397f56c4258b9611b5a50 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Tue, 20 Feb 2007 15:48:06 +0300 Subject: ACPI: battery: make internal names consistent with battery "state" Cleanup -- No functional changes. Battery state is currently exported in a proc "state" file. Update associated #defines and routines to be consistent. Signed-off-by: Vladimir Lebedev Signed-off-by: Len Brown --- drivers/acpi/battery.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index e64c76c8b7..df04f87dd4 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -44,7 +44,7 @@ #define ACPI_BATTERY_HID "PNP0C0A" #define ACPI_BATTERY_DEVICE_NAME "Battery" #define ACPI_BATTERY_FILE_INFO "info" -#define ACPI_BATTERY_FILE_STATUS "state" +#define ACPI_BATTERY_FILE_STATE "state" #define ACPI_BATTERY_FILE_ALARM "alarm" #define ACPI_BATTERY_NOTIFY_STATUS 0x80 #define ACPI_BATTERY_NOTIFY_INFO 0x81 @@ -76,7 +76,7 @@ static struct acpi_driver acpi_battery_driver = { }, }; -struct acpi_battery_status { +struct acpi_battery_state { acpi_integer state; acpi_integer present_rate; acpi_integer remaining_capacity; @@ -183,8 +183,8 @@ acpi_battery_get_info(struct acpi_battery *battery, } static int -acpi_battery_get_status(struct acpi_battery *battery, - struct acpi_battery_status **bst) +acpi_battery_get_state(struct acpi_battery *battery, + struct acpi_battery_state **bst) { int result = 0; acpi_status status = 0; @@ -425,7 +425,7 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) { int result = 0; struct acpi_battery *battery = seq->private; - struct acpi_battery_status *bst = NULL; + struct acpi_battery_state *bst = NULL; char *units = "?"; @@ -449,9 +449,9 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) /* Battery Status (_BST) */ - result = acpi_battery_get_status(battery, &bst); + result = acpi_battery_get_state(battery, &bst); if (result || !bst) { - seq_printf(seq, "ERROR: Unable to read battery status\n"); + seq_printf(seq, "ERROR: Unable to read battery state\n"); goto end; } @@ -621,7 +621,7 @@ static int acpi_battery_add_fs(struct acpi_device *device) } /* 'status' [R] */ - entry = create_proc_entry(ACPI_BATTERY_FILE_STATUS, + entry = create_proc_entry(ACPI_BATTERY_FILE_STATE, S_IRUGO, acpi_device_dir(device)); if (!entry) return -ENODEV; @@ -652,7 +652,7 @@ static int acpi_battery_remove_fs(struct acpi_device *device) if (acpi_device_dir(device)) { remove_proc_entry(ACPI_BATTERY_FILE_ALARM, acpi_device_dir(device)); - remove_proc_entry(ACPI_BATTERY_FILE_STATUS, + remove_proc_entry(ACPI_BATTERY_FILE_STATE, acpi_device_dir(device)); remove_proc_entry(ACPI_BATTERY_FILE_INFO, acpi_device_dir(device)); -- cgit v1.2.2 From b6ce4083ed8e2a01a3a59301eabe0fc1e68a8a84 Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Tue, 20 Feb 2007 15:48:06 +0300 Subject: ACPI: Cache battery status instead of re-evaluating AML /proc exports _BST in a single file, and _BST is re-evaulated whenever that file is read. Sometimes user-space reads this file frequently, and on some systems _BST takes a long time to evaluate due to a slow EC. Further, when we move to sysfs, the values returned from _BST will be in multiple files, and evaluating _BST for each file read would make matters worse. Here code is added to support caching the results of _BST. A new module parameter "update_time" tells how many seconds the cached _BST should be used before it is re-evaluated. Currently, update_time defaults to 0, and so the existing behaviour of re-evaluating on each read retained. Signed-off-by: Vladimir Lebedev Signed-off-by: Len Brown --- drivers/acpi/battery.c | 613 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 441 insertions(+), 172 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index df04f87dd4..f3b0024e57 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -52,12 +52,24 @@ #define ACPI_BATTERY_UNITS_AMPS "mA" #define _COMPONENT ACPI_BATTERY_COMPONENT + +#define ACPI_BATTERY_UPDATE_TIME 0 + +#define ACPI_BATTERY_NONE_UPDATE 0 +#define ACPI_BATTERY_EASY_UPDATE 1 +#define ACPI_BATTERY_INIT_UPDATE 2 + ACPI_MODULE_NAME("battery"); MODULE_AUTHOR("Paul Diefenbaugh"); MODULE_DESCRIPTION("ACPI Battery Driver"); MODULE_LICENSE("GPL"); +static unsigned int update_time = ACPI_BATTERY_UPDATE_TIME; + +/* 0 - every time, > 0 - by update_time */ +module_param(update_time, uint, 0644); + extern struct proc_dir_entry *acpi_lock_battery_dir(void); extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); @@ -100,32 +112,117 @@ struct acpi_battery_info { }; struct acpi_battery_flags { - u8 present:1; /* Bay occupied? */ - u8 power_unit:1; /* 0=watts, 1=apms */ - u8 alarm:1; /* _BTP present? */ - u8 reserved:5; -}; - -struct acpi_battery_trips { - unsigned long warning; - unsigned long low; + u8 battery_present_prev; + u8 alarm_present; + u8 init_update; + u8 info_update; + u8 state_update; + u8 alarm_update; + u8 power_unit; }; struct acpi_battery { + struct mutex mutex; struct acpi_device * device; struct acpi_battery_flags flags; - struct acpi_battery_trips trips; + struct acpi_buffer bif_data; + struct acpi_buffer bst_data; unsigned long alarm; - struct acpi_battery_info *info; + unsigned long info_update_time; + unsigned long state_update_time; + unsigned long alarm_update_time; }; +#define acpi_battery_present(battery) battery->device->status.battery_present +#define acpi_battery_present_prev(battery) battery->flags.battery_present_prev +#define acpi_battery_alarm_present(battery) battery->flags.alarm_present +#define acpi_battery_init_update_flag(battery) battery->flags.init_update +#define acpi_battery_info_update_flag(battery) battery->flags.info_update +#define acpi_battery_state_update_flag(battery) battery->flags.state_update +#define acpi_battery_alarm_update_flag(battery) battery->flags.alarm_update +#define acpi_battery_power_units(battery) battery->flags.power_unit ? \ + ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS +#define acpi_battery_handle(battery) battery->device->handle +#define acpi_battery_inserted(battery) (!acpi_battery_present_prev(battery) & acpi_battery_present(battery)) +#define acpi_battery_removed(battery) (acpi_battery_present_prev(battery) & !acpi_battery_present(battery)) +#define acpi_battery_bid(battery) acpi_device_bid(battery->device) +#define acpi_battery_status_str(battery) acpi_battery_present(battery) ? "present" : "absent" + /* -------------------------------------------------------------------------- Battery Management -------------------------------------------------------------------------- */ -static int -acpi_battery_get_info(struct acpi_battery *battery, - struct acpi_battery_info **bif) +static void acpi_battery_mutex_lock(struct acpi_battery *battery) +{ + mutex_lock(&battery->mutex); +} + +static void acpi_battery_mutex_unlock(struct acpi_battery *battery) +{ + mutex_unlock(&battery->mutex); +} + +static void acpi_battery_check_result(struct acpi_battery *battery, int result) +{ + if (!battery) + return; + + if (result) { + acpi_battery_init_update_flag(battery) = 1; + } +} + +static int acpi_battery_extract_package(struct acpi_battery *battery, + union acpi_object *package, + struct acpi_buffer *format, + struct acpi_buffer *data, + char *package_name) +{ + acpi_status status = AE_OK; + struct acpi_buffer data_null = { 0, NULL }; + + status = acpi_extract_package(package, format, &data_null); + if (status != AE_BUFFER_OVERFLOW) { + ACPI_EXCEPTION((AE_INFO, status, "Extracting size %s", + package_name)); + return -ENODEV; + } + + if (data_null.length != data->length) { + if (data->pointer) { + kfree(data->pointer); + } + data->pointer = kzalloc(data_null.length, GFP_KERNEL); + if (!data->pointer) { + ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()")); + return -ENOMEM; + } + data->length = data_null.length; + } + + status = acpi_extract_package(package, format, data); + if (ACPI_FAILURE(status)) { + ACPI_EXCEPTION((AE_INFO, status, "Extracting %s", + package_name)); + return -ENODEV; + } + + return 0; +} + +static int acpi_battery_get_status(struct acpi_battery *battery) +{ + int result = 0; + + result = acpi_bus_get_status(battery->device); + if (result) { + ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA")); + return -ENODEV; + } + return result; +} + +static int acpi_battery_get_info(struct acpi_battery *battery) { int result = 0; acpi_status status = 0; @@ -133,16 +230,18 @@ acpi_battery_get_info(struct acpi_battery *battery, struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BIF), ACPI_BATTERY_FORMAT_BIF }; - struct acpi_buffer data = { 0, NULL }; union acpi_object *package = NULL; + struct acpi_buffer *data = NULL; + struct acpi_battery_info *bif = NULL; + battery->info_update_time = get_seconds(); - if (!battery || !bif) - return -EINVAL; + if (!acpi_battery_present(battery)) + return 0; /* Evalute _BIF */ - status = acpi_evaluate_object(battery->device->handle, "_BIF", NULL, &buffer); + status = acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL, &buffer); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); return -ENODEV; @@ -150,41 +249,29 @@ acpi_battery_get_info(struct acpi_battery *battery, package = buffer.pointer; + data = &battery->bif_data; + /* Extract Package Data */ - status = acpi_extract_package(package, &format, &data); - if (status != AE_BUFFER_OVERFLOW) { - ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF")); - result = -ENODEV; + result = acpi_battery_extract_package(battery, package, &format, data, "_BIF"); + if (result) goto end; - } - data.pointer = kzalloc(data.length, GFP_KERNEL); - if (!data.pointer) { - result = -ENOMEM; - goto end; - } + end: - status = acpi_extract_package(package, &format, &data); - if (ACPI_FAILURE(status)) { - ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF")); - kfree(data.pointer); - result = -ENODEV; - goto end; + if (buffer.pointer) { + kfree(buffer.pointer); } - end: - kfree(buffer.pointer); - - if (!result) - (*bif) = data.pointer; + if (!result) { + bif = data->pointer; + battery->flags.power_unit = bif->power_unit; + } return result; } -static int -acpi_battery_get_state(struct acpi_battery *battery, - struct acpi_battery_state **bst) +static int acpi_battery_get_state(struct acpi_battery *battery) { int result = 0; acpi_status status = 0; @@ -192,16 +279,17 @@ acpi_battery_get_state(struct acpi_battery *battery, struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BST), ACPI_BATTERY_FORMAT_BST }; - struct acpi_buffer data = { 0, NULL }; union acpi_object *package = NULL; + struct acpi_buffer *data = NULL; + battery->state_update_time = get_seconds(); - if (!battery || !bst) - return -EINVAL; + if (!acpi_battery_present(battery)) + return 0; /* Evalute _BST */ - status = acpi_evaluate_object(battery->device->handle, "_BST", NULL, &buffer); + status = acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL, &buffer); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); return -ENODEV; @@ -209,55 +297,46 @@ acpi_battery_get_state(struct acpi_battery *battery, package = buffer.pointer; - /* Extract Package Data */ + data = &battery->bst_data; - status = acpi_extract_package(package, &format, &data); - if (status != AE_BUFFER_OVERFLOW) { - ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST")); - result = -ENODEV; - goto end; - } + /* Extract Package Data */ - data.pointer = kzalloc(data.length, GFP_KERNEL); - if (!data.pointer) { - result = -ENOMEM; + result = acpi_battery_extract_package(battery, package, &format, data, "_BST"); + if (result) goto end; - } - status = acpi_extract_package(package, &format, &data); - if (ACPI_FAILURE(status)) { - ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST")); - kfree(data.pointer); - result = -ENODEV; - goto end; + end: + if (buffer.pointer) { + kfree(buffer.pointer); } - end: - kfree(buffer.pointer); + return result; +} - if (!result) - (*bst) = data.pointer; +static int acpi_battery_get_alarm(struct acpi_battery *battery) +{ + battery->alarm_update_time = get_seconds(); - return result; + return 0; } -static int -acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm) +static int acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm) { acpi_status status = 0; union acpi_object arg0 = { ACPI_TYPE_INTEGER }; struct acpi_object_list arg_list = { 1, &arg0 }; + battery->alarm_update_time = get_seconds(); - if (!battery) - return -EINVAL; + if (!acpi_battery_present(battery)) + return -ENODEV; - if (!battery->flags.alarm) + if (!acpi_battery_alarm_present(battery)) return -ENODEV; arg0.integer.value = alarm; - status = acpi_evaluate_object(battery->device->handle, "_BTP", &arg_list, NULL); + status = acpi_evaluate_object(acpi_battery_handle(battery), "_BTP", &arg_list, NULL); if (ACPI_FAILURE(status)) return -ENODEV; @@ -268,65 +347,110 @@ acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm) return 0; } -static int acpi_battery_check(struct acpi_battery *battery) +static int acpi_battery_init_alarm(struct acpi_battery *battery) { int result = 0; acpi_status status = AE_OK; acpi_handle handle = NULL; - struct acpi_device *device = NULL; - struct acpi_battery_info *bif = NULL; - + struct acpi_battery_info *bif = battery->bif_data.pointer; + unsigned long alarm = battery->alarm; - if (!battery) - return -EINVAL; + /* See if alarms are supported, and if so, set default */ - device = battery->device; + status = acpi_get_handle(acpi_battery_handle(battery), "_BTP", &handle); + if (ACPI_SUCCESS(status)) { + acpi_battery_alarm_present(battery) = 1; + if (!alarm && bif) { + alarm = bif->design_capacity_warning; + } + result = acpi_battery_set_alarm(battery, alarm); + if (result) + goto end; + } else { + acpi_battery_alarm_present(battery) = 0; + } - result = acpi_bus_get_status(device); - if (result) - return result; + end: - /* Insertion? */ + return result; +} - if (!battery->flags.present && device->status.battery_present) { +static int acpi_battery_init_update(struct acpi_battery *battery) +{ + int result = 0; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Battery inserted\n")); + result = acpi_battery_get_status(battery); + if (result) + return result; - /* Evalute _BIF to get certain static information */ + acpi_battery_present_prev(battery) = acpi_battery_present(battery); - result = acpi_battery_get_info(battery, &bif); + if (acpi_battery_present(battery)) { + result = acpi_battery_get_info(battery); + if (result) + return result; + result = acpi_battery_get_state(battery); if (result) return result; - battery->flags.power_unit = bif->power_unit; - battery->trips.warning = bif->design_capacity_warning; - battery->trips.low = bif->design_capacity_low; - kfree(bif); + acpi_battery_init_alarm(battery); + } + + return result; +} + +static int acpi_battery_update(struct acpi_battery *battery, + int update, int *update_result_ptr) +{ + int result = 0; + int update_result = ACPI_BATTERY_NONE_UPDATE; - /* See if alarms are supported, and if so, set default */ + if (!acpi_battery_present(battery)) { + update = 1; + } - status = acpi_get_handle(battery->device->handle, "_BTP", &handle); - if (ACPI_SUCCESS(status)) { - battery->flags.alarm = 1; - acpi_battery_set_alarm(battery, battery->trips.warning); + if (acpi_battery_init_update_flag(battery)) { + result = acpi_battery_init_update(battery); + if (result) + goto end;; + update_result = ACPI_BATTERY_INIT_UPDATE; + } else if (update) { + result = acpi_battery_get_status(battery); + if (result) + goto end;; + if (acpi_battery_inserted(battery) || acpi_battery_removed(battery)) { + result = acpi_battery_init_update(battery); + if (result) + goto end;; + update_result = ACPI_BATTERY_INIT_UPDATE; + } else { + update_result = ACPI_BATTERY_EASY_UPDATE; } } - /* Removal? */ + end: - else if (battery->flags.present && !device->status.battery_present) { - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Battery removed\n")); - } + acpi_battery_init_update_flag(battery) = (result != 0); - battery->flags.present = device->status.battery_present; + *update_result_ptr = update_result; return result; } -static void acpi_battery_check_present(struct acpi_battery *battery) +static void acpi_battery_notify_update(struct acpi_battery *battery) { - if (!battery->flags.present) { - acpi_battery_check(battery); + acpi_battery_get_status(battery); + + if (acpi_battery_init_update_flag(battery)) { + return; + } + + if (acpi_battery_inserted(battery) || acpi_battery_removed(battery)) { + acpi_battery_init_update_flag(battery) = 1; + } else { + acpi_battery_info_update_flag(battery) = 1; + acpi_battery_state_update_flag(battery) = 1; + acpi_battery_alarm_update_flag(battery) = 1; } } @@ -335,37 +459,33 @@ static void acpi_battery_check_present(struct acpi_battery *battery) -------------------------------------------------------------------------- */ static struct proc_dir_entry *acpi_battery_dir; -static int acpi_battery_read_info(struct seq_file *seq, void *offset) + +static int acpi_battery_read_info_print(struct seq_file *seq, int result) { - int result = 0; struct acpi_battery *battery = seq->private; struct acpi_battery_info *bif = NULL; char *units = "?"; - - if (!battery) + if (result) goto end; - acpi_battery_check_present(battery); - - if (battery->flags.present) + if (acpi_battery_present(battery)) seq_printf(seq, "present: yes\n"); else { seq_printf(seq, "present: no\n"); goto end; } - /* Battery Info (_BIF) */ - - result = acpi_battery_get_info(battery, &bif); - if (result || !bif) { - seq_printf(seq, "ERROR: Unable to read battery information\n"); + bif = battery->bif_data.pointer; + if (!bif) { + ACPI_EXCEPTION((AE_INFO, AE_ERROR, "BIF buffer is NULL")); + result = -ENODEV; goto end; } - units = - bif-> - power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS; + /* Battery Units */ + + units = acpi_battery_power_units(battery); if (bif->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN) seq_printf(seq, "design capacity: unknown\n"); @@ -396,7 +516,6 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset) else seq_printf(seq, "design voltage: %d mV\n", (u32) bif->design_voltage); - seq_printf(seq, "design capacity warning: %d %sh\n", (u32) bif->design_capacity_warning, units); seq_printf(seq, "design capacity low: %d %sh\n", @@ -411,9 +530,48 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset) seq_printf(seq, "OEM info: %s\n", bif->oem_info); end: - kfree(bif); - return 0; + if (result) + seq_printf(seq, "ERROR: Unable to read battery info\n"); + + return result; +} + +static int acpi_battery_read_info(struct seq_file *seq, void *offset) +{ + struct acpi_battery *battery = seq->private; + int result = 0; + int update_result = ACPI_BATTERY_NONE_UPDATE; + int update = 0; + + acpi_battery_mutex_lock(battery); + + update = (get_seconds() - battery->info_update_time >= update_time); + update = (update | acpi_battery_info_update_flag(battery)); + + result = acpi_battery_update(battery, update, &update_result); + if (result) + goto end; + + /* Battery Info (_BIF) */ + + if (update_result == ACPI_BATTERY_EASY_UPDATE) { + result = acpi_battery_get_info(battery); + if (result) + goto end; + } + + end: + + result = acpi_battery_read_info_print(seq, result); + + acpi_battery_check_result(battery, result); + + acpi_battery_info_update_flag(battery) = result; + + acpi_battery_mutex_unlock(battery); + + return result; } static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) @@ -421,40 +579,33 @@ static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) return single_open(file, acpi_battery_read_info, PDE(inode)->data); } -static int acpi_battery_read_state(struct seq_file *seq, void *offset) +static int acpi_battery_read_state_print(struct seq_file *seq, int result) { - int result = 0; struct acpi_battery *battery = seq->private; struct acpi_battery_state *bst = NULL; char *units = "?"; - - if (!battery) + if (result) goto end; - acpi_battery_check_present(battery); - - if (battery->flags.present) + if (acpi_battery_present(battery)) seq_printf(seq, "present: yes\n"); else { seq_printf(seq, "present: no\n"); goto end; } - /* Battery Units */ - - units = - battery->flags. - power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS; - - /* Battery Status (_BST) */ - - result = acpi_battery_get_state(battery, &bst); - if (result || !bst) { - seq_printf(seq, "ERROR: Unable to read battery state\n"); + bst = battery->bst_data.pointer; + if (!bst) { + ACPI_EXCEPTION((AE_INFO, AE_ERROR, "BST buffer is NULL")); + result = -ENODEV; goto end; } + /* Battery Units */ + + units = acpi_battery_power_units(battery); + if (!(bst->state & 0x04)) seq_printf(seq, "capacity state: ok\n"); else @@ -490,9 +641,49 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset) (u32) bst->present_voltage); end: - kfree(bst); - return 0; + if (result) { + seq_printf(seq, "ERROR: Unable to read battery state\n"); + } + + return result; +} + +static int acpi_battery_read_state(struct seq_file *seq, void *offset) +{ + struct acpi_battery *battery = seq->private; + int result = 0; + int update_result = ACPI_BATTERY_NONE_UPDATE; + int update = 0; + + acpi_battery_mutex_lock(battery); + + update = (get_seconds() - battery->state_update_time >= update_time); + update = (update | acpi_battery_state_update_flag(battery)); + + result = acpi_battery_update(battery, update, &update_result); + if (result) + goto end; + + /* Battery State (_BST) */ + + if (update_result == ACPI_BATTERY_EASY_UPDATE) { + result = acpi_battery_get_state(battery); + if (result) + goto end; + } + + end: + + result = acpi_battery_read_state_print(seq, result); + + acpi_battery_check_result(battery, result); + + acpi_battery_state_update_flag(battery) = result; + + acpi_battery_mutex_unlock(battery); + + return result; } static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) @@ -500,38 +691,72 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) return single_open(file, acpi_battery_read_state, PDE(inode)->data); } -static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) +static int acpi_battery_read_alarm_print(struct seq_file *seq, int result) { struct acpi_battery *battery = seq->private; char *units = "?"; - - if (!battery) + if (result) goto end; - acpi_battery_check_present(battery); - - if (!battery->flags.present) { + if (!acpi_battery_present(battery)) { seq_printf(seq, "present: no\n"); goto end; } /* Battery Units */ - units = - battery->flags. - power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS; - - /* Battery Alarm */ + units = acpi_battery_power_units(battery); seq_printf(seq, "alarm: "); if (!battery->alarm) seq_printf(seq, "unsupported\n"); else - seq_printf(seq, "%d %sh\n", (u32) battery->alarm, units); + seq_printf(seq, "%lu %sh\n", battery->alarm, units); end: - return 0; + + if (result) + seq_printf(seq, "ERROR: Unable to read battery alarm\n"); + + return result; +} + +static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) +{ + struct acpi_battery *battery = seq->private; + int result = 0; + int update_result = ACPI_BATTERY_NONE_UPDATE; + int update = 0; + + acpi_battery_mutex_lock(battery); + + update = (get_seconds() - battery->alarm_update_time >= update_time); + update = (update | acpi_battery_alarm_update_flag(battery)); + + result = acpi_battery_update(battery, update, &update_result); + if (result) + goto end; + + /* Battery Alarm */ + + if (update_result == ACPI_BATTERY_EASY_UPDATE) { + result = acpi_battery_get_alarm(battery); + if (result) + goto end; + } + + end: + + result = acpi_battery_read_alarm_print(seq, result); + + acpi_battery_check_result(battery, result); + + acpi_battery_alarm_update_flag(battery) = result; + + acpi_battery_mutex_unlock(battery); + + return result; } static ssize_t @@ -543,27 +768,47 @@ acpi_battery_write_alarm(struct file *file, char alarm_string[12] = { '\0' }; struct seq_file *m = file->private_data; struct acpi_battery *battery = m->private; + int update_result = ACPI_BATTERY_NONE_UPDATE; if (!battery || (count > sizeof(alarm_string) - 1)) return -EINVAL; - acpi_battery_check_present(battery); + acpi_battery_mutex_lock(battery); - if (!battery->flags.present) - return -ENODEV; + result = acpi_battery_update(battery, 1, &update_result); + if (result) { + result = -ENODEV; + goto end; + } - if (copy_from_user(alarm_string, buffer, count)) - return -EFAULT; + if (!acpi_battery_present(battery)) { + result = -ENODEV; + goto end; + } + + if (copy_from_user(alarm_string, buffer, count)) { + result = -EFAULT; + goto end; + } alarm_string[count] = '\0'; result = acpi_battery_set_alarm(battery, simple_strtoul(alarm_string, NULL, 0)); if (result) - return result; + goto end; + + end: + + acpi_battery_check_result(battery, result); - return count; + if (!result) + result = count; + + acpi_battery_mutex_unlock(battery); + + return result; } static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) @@ -648,7 +893,6 @@ static int acpi_battery_add_fs(struct acpi_device *device) static int acpi_battery_remove_fs(struct acpi_device *device) { - if (acpi_device_dir(device)) { remove_proc_entry(ACPI_BATTERY_FILE_ALARM, acpi_device_dir(device)); @@ -684,8 +928,11 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) case ACPI_BATTERY_NOTIFY_INFO: case ACPI_NOTIFY_BUS_CHECK: case ACPI_NOTIFY_DEVICE_CHECK: - acpi_battery_check(battery); - acpi_bus_generate_event(device, event, battery->flags.present); + acpi_battery_mutex_lock(battery); + device = battery->device; + acpi_battery_notify_update(battery); + acpi_battery_mutex_unlock(battery); + acpi_bus_generate_event(device, event, acpi_battery_present(battery)); break; default: ACPI_DEBUG_PRINT((ACPI_DB_INFO, @@ -702,7 +949,6 @@ static int acpi_battery_add(struct acpi_device *device) acpi_status status = 0; struct acpi_battery *battery = NULL; - if (!device) return -EINVAL; @@ -710,15 +956,21 @@ static int acpi_battery_add(struct acpi_device *device) if (!battery) return -ENOMEM; + mutex_init(&battery->mutex); + + acpi_battery_mutex_lock(battery); + battery->device = device; strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); acpi_driver_data(device) = battery; - result = acpi_battery_check(battery); + result = acpi_battery_get_status(battery); if (result) goto end; + acpi_battery_init_update_flag(battery) = 1; + result = acpi_battery_add_fs(device); if (result) goto end; @@ -727,6 +979,7 @@ static int acpi_battery_add(struct acpi_device *device) ACPI_ALL_NOTIFY, acpi_battery_notify, battery); if (ACPI_FAILURE(status)) { + ACPI_EXCEPTION((AE_INFO, status, "Installing notify handler")); result = -ENODEV; goto end; } @@ -736,11 +989,14 @@ static int acpi_battery_add(struct acpi_device *device) device->status.battery_present ? "present" : "absent"); end: + if (result) { acpi_battery_remove_fs(device); kfree(battery); } + acpi_battery_mutex_unlock(battery); + return result; } @@ -749,18 +1005,29 @@ static int acpi_battery_remove(struct acpi_device *device, int type) acpi_status status = 0; struct acpi_battery *battery = NULL; - if (!device || !acpi_driver_data(device)) return -EINVAL; battery = acpi_driver_data(device); + acpi_battery_mutex_lock(battery); + status = acpi_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY, acpi_battery_notify); acpi_battery_remove_fs(device); + if (battery->bif_data.pointer) + kfree(battery->bif_data.pointer); + + if (battery->bst_data.pointer) + kfree(battery->bst_data.pointer); + + acpi_battery_mutex_unlock(battery); + + mutex_destroy(&battery->mutex); + kfree(battery); return 0; @@ -775,7 +1042,10 @@ static int acpi_battery_resume(struct acpi_device *device) return -EINVAL; battery = device->driver_data; - return acpi_battery_check(battery); + + acpi_battery_init_update_flag(battery) = 1; + + return 0; } static int __init acpi_battery_init(void) @@ -800,7 +1070,6 @@ static int __init acpi_battery_init(void) static void __exit acpi_battery_exit(void) { - acpi_bus_unregister_driver(&acpi_battery_driver); acpi_unlock_battery_dir(acpi_battery_dir); -- cgit v1.2.2 From 9ea7d57576f40c6af03c8c9fa7a069f2222b498b Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Tue, 20 Feb 2007 15:48:06 +0300 Subject: ACPI: battery: Lindent Signed-off-by: Vladimir Lebedev Signed-off-by: Len Brown --- drivers/acpi/battery.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index f3b0024e57..fc9c50ab52 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -123,7 +123,7 @@ struct acpi_battery_flags { struct acpi_battery { struct mutex mutex; - struct acpi_device * device; + struct acpi_device *device; struct acpi_battery_flags flags; struct acpi_buffer bif_data; struct acpi_buffer bst_data; @@ -241,7 +241,9 @@ static int acpi_battery_get_info(struct acpi_battery *battery) /* Evalute _BIF */ - status = acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL, &buffer); + status = + acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL, + &buffer); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); return -ENODEV; @@ -253,7 +255,9 @@ static int acpi_battery_get_info(struct acpi_battery *battery) /* Extract Package Data */ - result = acpi_battery_extract_package(battery, package, &format, data, "_BIF"); + result = + acpi_battery_extract_package(battery, package, &format, data, + "_BIF"); if (result) goto end; @@ -289,7 +293,9 @@ static int acpi_battery_get_state(struct acpi_battery *battery) /* Evalute _BST */ - status = acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL, &buffer); + status = + acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL, + &buffer); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); return -ENODEV; @@ -301,7 +307,9 @@ static int acpi_battery_get_state(struct acpi_battery *battery) /* Extract Package Data */ - result = acpi_battery_extract_package(battery, package, &format, data, "_BST"); + result = + acpi_battery_extract_package(battery, package, &format, data, + "_BST"); if (result) goto end; @@ -320,7 +328,8 @@ static int acpi_battery_get_alarm(struct acpi_battery *battery) return 0; } -static int acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm) +static int acpi_battery_set_alarm(struct acpi_battery *battery, + unsigned long alarm) { acpi_status status = 0; union acpi_object arg0 = { ACPI_TYPE_INTEGER }; @@ -336,7 +345,9 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long al arg0.integer.value = alarm; - status = acpi_evaluate_object(acpi_battery_handle(battery), "_BTP", &arg_list, NULL); + status = + acpi_evaluate_object(acpi_battery_handle(battery), "_BTP", + &arg_list, NULL); if (ACPI_FAILURE(status)) return -ENODEV; @@ -400,7 +411,7 @@ static int acpi_battery_init_update(struct acpi_battery *battery) } static int acpi_battery_update(struct acpi_battery *battery, - int update, int *update_result_ptr) + int update, int *update_result_ptr) { int result = 0; int update_result = ACPI_BATTERY_NONE_UPDATE; @@ -418,7 +429,8 @@ static int acpi_battery_update(struct acpi_battery *battery, result = acpi_battery_get_status(battery); if (result) goto end;; - if (acpi_battery_inserted(battery) || acpi_battery_removed(battery)) { + if (acpi_battery_inserted(battery) + || acpi_battery_removed(battery)) { result = acpi_battery_init_update(battery); if (result) goto end;; @@ -770,7 +782,6 @@ acpi_battery_write_alarm(struct file *file, struct acpi_battery *battery = m->private; int update_result = ACPI_BATTERY_NONE_UPDATE; - if (!battery || (count > sizeof(alarm_string) - 1)) return -EINVAL; @@ -845,7 +856,6 @@ static int acpi_battery_add_fs(struct acpi_device *device) { struct proc_dir_entry *entry = NULL; - if (!acpi_device_dir(device)) { acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), acpi_battery_dir); @@ -917,7 +927,6 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) struct acpi_battery *battery = data; struct acpi_device *device = NULL; - if (!battery) return; @@ -932,7 +941,8 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) device = battery->device; acpi_battery_notify_update(battery); acpi_battery_mutex_unlock(battery); - acpi_bus_generate_event(device, event, acpi_battery_present(battery)); + acpi_bus_generate_event(device, event, + acpi_battery_present(battery)); break; default: ACPI_DEBUG_PRINT((ACPI_DB_INFO, -- cgit v1.2.2 From 6eedeef73e7fff32eb5fa25178c3c77b1db0ec0f Mon Sep 17 00:00:00 2001 From: Vladimir Lebedev Date: Sat, 21 Apr 2007 22:41:48 -0400 Subject: process reading battery status hangs http://bugzilla.kernel.org/show_bug.cgi?id=8351 Signed-off-by: Vladimir Lebedev Signed-off-by: Len Brown --- drivers/acpi/battery.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index fc9c50ab52..b5df318978 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -937,10 +937,8 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) case ACPI_BATTERY_NOTIFY_INFO: case ACPI_NOTIFY_BUS_CHECK: case ACPI_NOTIFY_DEVICE_CHECK: - acpi_battery_mutex_lock(battery); device = battery->device; acpi_battery_notify_update(battery); - acpi_battery_mutex_unlock(battery); acpi_bus_generate_event(device, event, acpi_battery_present(battery)); break; -- cgit v1.2.2 From 23b0f015bf2c050b8b5399430ca64e1b3398cf76 Mon Sep 17 00:00:00 2001 From: Luming Yu Date: Wed, 9 May 2007 21:07:05 +0800 Subject: ACPI: video: output switch sysfs support Requires CONFIG_VIDEO_OUTPUT_CONTROL and CONFIG_ACPI_VIDEO. After loading output.ko and video.ko, you would have /sys/class/video_output and several device acpi_videoNum there. For example, I got acpi_video0, acpi_video1,acpi_video2,and acpi_video3 under /sys/class/video_output on my T40. I can query the status of output device0 by running " cat /sys/class/video_output/acpi_video0 " The return value is defined in ACPI SPEC B.5.5 _DCS(Return the Status of Output Device). Also you can turn off video1 and turn on video0 by " echo 0 > acpi_video1; echo 0x80000000 > acpi_video0". Please reference ACPI SPEC B.5.7 _DSS for the parameter definition. Please note that it may or may NOT works purely depending on if your vendor providing correct ACPI video extension support in bios. the driver output.ko and video.ko just works like a interface to invoke BIOS. Signed-off-by: Luming Yu Signed-off-by: Len Brown --- drivers/acpi/Kconfig | 2 +- drivers/acpi/video.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/video/Kconfig | 7 +++++++ drivers/video/Makefile | 3 +++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 139f41f033..eb4855f2c6 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -124,7 +124,7 @@ config ACPI_BUTTON config ACPI_VIDEO tristate "Video" - depends on X86 && BACKLIGHT_CLASS_DEVICE + depends on X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL help This driver implement the ACPI Extensions For Display Adapters for integrated graphics devices on motherboard, as specified in diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index 00d25b3472..39273dae70 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c @@ -33,6 +33,7 @@ #include #include +#include #include #include @@ -169,6 +170,7 @@ struct acpi_video_device { struct acpi_device *dev; struct acpi_video_device_brightness *brightness; struct backlight_device *backlight; + struct output_device *output_dev; }; /* bus */ @@ -272,6 +274,10 @@ static int acpi_video_get_next_level(struct acpi_video_device *device, u32 level_current, u32 event); static void acpi_video_switch_brightness(struct acpi_video_device *device, int event); +static int acpi_video_device_get_state(struct acpi_video_device *device, + unsigned long *state); +static int acpi_video_output_get(struct output_device *od); +static int acpi_video_device_set_state(struct acpi_video_device *device, int state); /*backlight device sysfs support*/ static int acpi_video_get_brightness(struct backlight_device *bd) @@ -297,6 +303,28 @@ static struct backlight_ops acpi_backlight_ops = { .update_status = acpi_video_set_brightness, }; +/*video output device sysfs support*/ +static int acpi_video_output_get(struct output_device *od) +{ + unsigned long state; + struct acpi_video_device *vd = + (struct acpi_video_device *)class_get_devdata(&od->class_dev); + acpi_video_device_get_state(vd, &state); + return (int)state; +} + +static int acpi_video_output_set(struct output_device *od) +{ + unsigned long state = od->request_state; + struct acpi_video_device *vd= + (struct acpi_video_device *)class_get_devdata(&od->class_dev); + return acpi_video_device_set_state(vd, state); +} + +static struct output_properties acpi_output_properties = { + .set_state = acpi_video_output_set, + .get_status = acpi_video_output_get, +}; /* -------------------------------------------------------------------------- Video Management -------------------------------------------------------------------------- */ @@ -626,6 +654,17 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device) kfree(name); } + if (device->cap._DCS && device->cap._DSS){ + static int count = 0; + char *name; + name = kzalloc(MAX_NAME_LEN, GFP_KERNEL); + if (!name) + return; + sprintf(name, "acpi_video%d", count++); + device->output_dev = video_output_register(name, + NULL, device, &acpi_output_properties); + kfree(name); + } return; } @@ -1669,6 +1708,7 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device) ACPI_DEVICE_NOTIFY, acpi_video_device_notify); backlight_device_unregister(device->backlight); + video_output_unregister(device->output_dev); return 0; } diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 1132ba5ff3..6c8ffe6757 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -11,6 +11,13 @@ config VGASTATE tristate default n +config VIDEO_OUTPUT_CONTROL + tristate "Lowlevel video output switch controls" + default m + help + This framework adds support for low-level control of the video + output switch. + config FB tristate "Support for frame buffer devices" ---help--- diff --git a/drivers/video/Makefile b/drivers/video/Makefile index a916c20427..08b7c26a57 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -119,3 +119,6 @@ obj-$(CONFIG_FB_OF) += offb.o # the test framebuffer is last obj-$(CONFIG_FB_VIRTUAL) += vfb.o + +#video output switch sysfs driver +obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o -- cgit v1.2.2 From 38ff4ffc039ba5a5878f2dcbb03d87c3a1f02f1b Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Wed, 9 May 2007 15:04:24 -0700 Subject: ACPI: dock: cleanup the uid patch Make uid sysfs file error path free memory, and cleanup sysfs file when removing driver. Also fix CodingStyle violations. Signed-off-by: Kristen Carlson Accardi Cc: Illya A. Volynets-Evenbakh Signed-off-by: Len Brown --- drivers/acpi/dock.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 4546bf873a..9ddc3f189b 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -675,16 +675,15 @@ static ssize_t show_dock_uid(struct device *dev, struct device_attribute *attr, char *buf) { unsigned long lbuf; - acpi_status status = acpi_evaluate_integer(dock_station->handle, "_UID", NULL, &lbuf); - if(ACPI_FAILURE(status)) { + acpi_status status = acpi_evaluate_integer(dock_station->handle, + "_UID", NULL, &lbuf); + if (ACPI_FAILURE(status)) return 0; - } + return snprintf(buf, PAGE_SIZE, "%lx\n", lbuf); } DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL); - - /** * dock_add - add a new dock station * @handle: the dock station handle @@ -736,6 +735,8 @@ static int dock_add(acpi_handle handle) ret = device_create_file(&dock_device.dev, &dev_attr_uid); if (ret) { printk("Error %d adding sysfs file\n", ret); + device_remove_file(&dock_device.dev, &dev_attr_docked); + device_remove_file(&dock_device.dev, &dev_attr_undock); platform_device_unregister(&dock_device); kfree(dock_station); return ret; @@ -775,6 +776,7 @@ dock_add_err: dock_add_err_unregister: device_remove_file(&dock_device.dev, &dev_attr_docked); device_remove_file(&dock_device.dev, &dev_attr_undock); + device_remove_file(&dock_device.dev, &dev_attr_uid); platform_device_unregister(&dock_device); kfree(dock_station); return ret; @@ -806,6 +808,7 @@ static int dock_remove(void) /* cleanup sysfs */ device_remove_file(&dock_device.dev, &dev_attr_docked); device_remove_file(&dock_device.dev, &dev_attr_undock); + device_remove_file(&dock_device.dev, &dev_attr_uid); platform_device_unregister(&dock_device); /* free dock station memory */ -- cgit v1.2.2 From 22fe4c2114e29477ca6738729c074ee8f60d3b73 Mon Sep 17 00:00:00 2001 From: Chuck Ebbert Date: Wed, 9 May 2007 15:05:48 -0700 Subject: ACPI: dock: fix opps after dock driver fails to initialize The driver tests the dock_station pointer for nonnull to check whether it has initialized properly. But in some cases dock_station will be non-null after being freed when driver init fails. Fix by zeroing the pointer after freeing. Signed-off-by: Chuck Ebbert Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 9ddc3f189b..f66f4f7767 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -715,6 +715,7 @@ static int dock_add(acpi_handle handle) if (ret) { printk(KERN_ERR PREFIX "Error %d registering dock device\n", ret); kfree(dock_station); + dock_station = NULL; return ret; } ret = device_create_file(&dock_device.dev, &dev_attr_docked); @@ -722,6 +723,7 @@ static int dock_add(acpi_handle handle) printk("Error %d adding sysfs file\n", ret); platform_device_unregister(&dock_device); kfree(dock_station); + dock_station = NULL; return ret; } ret = device_create_file(&dock_device.dev, &dev_attr_undock); @@ -730,6 +732,7 @@ static int dock_add(acpi_handle handle) device_remove_file(&dock_device.dev, &dev_attr_docked); platform_device_unregister(&dock_device); kfree(dock_station); + dock_station = NULL; return ret; } ret = device_create_file(&dock_device.dev, &dev_attr_uid); @@ -739,6 +742,7 @@ static int dock_add(acpi_handle handle) device_remove_file(&dock_device.dev, &dev_attr_undock); platform_device_unregister(&dock_device); kfree(dock_station); + dock_station = NULL; return ret; } @@ -751,6 +755,7 @@ static int dock_add(acpi_handle handle) dd = alloc_dock_dependent_device(handle); if (!dd) { kfree(dock_station); + dock_station = NULL; ret = -ENOMEM; goto dock_add_err_unregister; } @@ -779,6 +784,7 @@ dock_add_err_unregister: device_remove_file(&dock_device.dev, &dev_attr_uid); platform_device_unregister(&dock_device); kfree(dock_station); + dock_station = NULL; return ret; } @@ -813,6 +819,7 @@ static int dock_remove(void) /* free dock station memory */ kfree(dock_station); + dock_station = NULL; return 0; } -- cgit v1.2.2 From 0f6f2804563eee64f0fc7cbcb009b98b6f332af6 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Wed, 9 May 2007 15:07:04 -0700 Subject: ACPI: dock: use dynamically allocated platform device Get rid of no release function warnings by switching to dynamically allocating the platform_device and using the platform device release routine in the base driver. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index f66f4f7767..b5addd411b 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -41,7 +41,7 @@ MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION); MODULE_LICENSE("GPL"); static struct atomic_notifier_head dock_notifier_list; -static struct platform_device dock_device; +static struct platform_device *dock_device; static char dock_device_name[] = "dock"; struct dock_station { @@ -327,7 +327,7 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event) static void dock_event(struct dock_station *ds, u32 event, int num) { - struct device *dev = &dock_device.dev; + struct device *dev = &dock_device->dev; /* * Indicate that the status of the dock station has * changed. @@ -710,37 +710,36 @@ static int dock_add(acpi_handle handle) ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); /* initialize platform device stuff */ - dock_device.name = dock_device_name; - ret = platform_device_register(&dock_device); - if (ret) { - printk(KERN_ERR PREFIX "Error %d registering dock device\n", ret); + dock_device = + platform_device_register_simple(dock_device_name, 0, NULL, 0); + if (IS_ERR(dock_device)) { kfree(dock_station); dock_station = NULL; - return ret; + return PTR_ERR(dock_device); } - ret = device_create_file(&dock_device.dev, &dev_attr_docked); + ret = device_create_file(&dock_device->dev, &dev_attr_docked); if (ret) { printk("Error %d adding sysfs file\n", ret); - platform_device_unregister(&dock_device); + platform_device_unregister(dock_device); kfree(dock_station); dock_station = NULL; return ret; } - ret = device_create_file(&dock_device.dev, &dev_attr_undock); + ret = device_create_file(&dock_device->dev, &dev_attr_undock); if (ret) { printk("Error %d adding sysfs file\n", ret); - device_remove_file(&dock_device.dev, &dev_attr_docked); - platform_device_unregister(&dock_device); + device_remove_file(&dock_device->dev, &dev_attr_docked); + platform_device_unregister(dock_device); kfree(dock_station); dock_station = NULL; return ret; } - ret = device_create_file(&dock_device.dev, &dev_attr_uid); + ret = device_create_file(&dock_device->dev, &dev_attr_uid); if (ret) { printk("Error %d adding sysfs file\n", ret); - device_remove_file(&dock_device.dev, &dev_attr_docked); - device_remove_file(&dock_device.dev, &dev_attr_undock); - platform_device_unregister(&dock_device); + device_remove_file(&dock_device->dev, &dev_attr_docked); + device_remove_file(&dock_device->dev, &dev_attr_undock); + platform_device_unregister(dock_device); kfree(dock_station); dock_station = NULL; return ret; @@ -779,10 +778,10 @@ static int dock_add(acpi_handle handle) dock_add_err: kfree(dd); dock_add_err_unregister: - device_remove_file(&dock_device.dev, &dev_attr_docked); - device_remove_file(&dock_device.dev, &dev_attr_undock); - device_remove_file(&dock_device.dev, &dev_attr_uid); - platform_device_unregister(&dock_device); + device_remove_file(&dock_device->dev, &dev_attr_docked); + device_remove_file(&dock_device->dev, &dev_attr_undock); + device_remove_file(&dock_device->dev, &dev_attr_uid); + platform_device_unregister(dock_device); kfree(dock_station); dock_station = NULL; return ret; @@ -812,10 +811,10 @@ static int dock_remove(void) printk(KERN_ERR "Error removing notify handler\n"); /* cleanup sysfs */ - device_remove_file(&dock_device.dev, &dev_attr_docked); - device_remove_file(&dock_device.dev, &dev_attr_undock); - device_remove_file(&dock_device.dev, &dev_attr_uid); - platform_device_unregister(&dock_device); + device_remove_file(&dock_device->dev, &dev_attr_docked); + device_remove_file(&dock_device->dev, &dev_attr_undock); + device_remove_file(&dock_device->dev, &dev_attr_uid); + platform_device_unregister(dock_device); /* free dock station memory */ kfree(dock_station); -- cgit v1.2.2 From a0cd35fdca0bb711854edeaf016cec6cdf82eeca Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Wed, 9 May 2007 15:08:15 -0700 Subject: ACPI: dock: add immediate_undock option Allow the driver to be loaded with an option that will allow userspace to control whether the laptop is ejected immediately when the user presses the button, or only when the syfs undock file is written. if immediate_undock == 1, then when the user presses the undock button, the laptop will send an event to userspace to notify userspace of the undock, but then immediately undock without waiting for userspace. This is the current behavior, and I set this to be the default. if immediate_undock == 0, then when the user presses the undock button, the laptop will send an event to userspace and do nothing. User space can query the "flags" sysfs entry to determine if an undock request has been made by the user (if bit 1 is set). User space will then need to write the undock sysfs entry to complete the undocking process. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index b5addd411b..98ec717b14 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -40,6 +40,13 @@ MODULE_AUTHOR("Kristen Carlson Accardi"); MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION); MODULE_LICENSE("GPL"); +static int immediate_undock = 1; +module_param(immediate_undock, bool, 0644); +MODULE_PARM_DESC(immediate_undock, "1 (default) will cause the driver to " + "undock immediately when the undock button is pressed, 0 will cause" + " the driver to wait for userspace to write the undock sysfs file " + " before undocking"); + static struct atomic_notifier_head dock_notifier_list; static struct platform_device *dock_device; static char dock_device_name[] = "dock"; @@ -63,6 +70,7 @@ struct dock_dependent_device { }; #define DOCK_DOCKING 0x00000001 +#define DOCK_UNDOCKING 0x00000002 #define DOCK_EVENT 3 #define UNDOCK_EVENT 2 @@ -420,6 +428,16 @@ static inline void complete_dock(struct dock_station *ds) ds->last_dock_time = jiffies; } +static inline void begin_undock(struct dock_station *ds) +{ + ds->flags |= DOCK_UNDOCKING; +} + +static inline void complete_undock(struct dock_station *ds) +{ + ds->flags &= ~(DOCK_UNDOCKING); +} + /** * dock_in_progress - see if we are in the middle of handling a dock event * @ds: the dock station @@ -550,7 +568,7 @@ static int handle_eject_request(struct dock_station *ds, u32 event) printk(KERN_ERR PREFIX "Unable to undock!\n"); return -EBUSY; } - + complete_undock(ds); return 0; } @@ -594,7 +612,11 @@ static void dock_notify(acpi_handle handle, u32 event, void *data) * to the driver who wish to hotplug. */ case ACPI_NOTIFY_EJECT_REQUEST: - handle_eject_request(ds, event); + begin_undock(ds); + if (immediate_undock) + handle_eject_request(ds, event); + else + dock_event(ds, event, UNDOCK_EVENT); break; default: printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); @@ -652,6 +674,17 @@ static ssize_t show_docked(struct device *dev, } DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); +/* + * show_flags - read method for flags file in sysfs + */ +static ssize_t show_flags(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags); + +} +DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL); + /* * write_undock - write method for "undock" file in sysfs */ @@ -717,6 +750,7 @@ static int dock_add(acpi_handle handle) dock_station = NULL; return PTR_ERR(dock_device); } + ret = device_create_file(&dock_device->dev, &dev_attr_docked); if (ret) { printk("Error %d adding sysfs file\n", ret); @@ -744,6 +778,17 @@ static int dock_add(acpi_handle handle) dock_station = NULL; return ret; } + ret = device_create_file(&dock_device->dev, &dev_attr_flags); + if (ret) { + printk("Error %d adding sysfs file\n", ret); + device_remove_file(&dock_device->dev, &dev_attr_docked); + device_remove_file(&dock_device->dev, &dev_attr_undock); + device_remove_file(&dock_device->dev, &dev_attr_uid); + platform_device_unregister(dock_device); + kfree(dock_station); + dock_station = NULL; + return ret; + } /* Find dependent devices */ acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, @@ -781,6 +826,7 @@ dock_add_err_unregister: device_remove_file(&dock_device->dev, &dev_attr_docked); device_remove_file(&dock_device->dev, &dev_attr_undock); device_remove_file(&dock_device->dev, &dev_attr_uid); + device_remove_file(&dock_device->dev, &dev_attr_flags); platform_device_unregister(dock_device); kfree(dock_station); dock_station = NULL; @@ -814,6 +860,7 @@ static int dock_remove(void) device_remove_file(&dock_device->dev, &dev_attr_docked); device_remove_file(&dock_device->dev, &dev_attr_undock); device_remove_file(&dock_device->dev, &dev_attr_uid); + device_remove_file(&dock_device->dev, &dev_attr_flags); platform_device_unregister(dock_device); /* free dock station memory */ -- cgit v1.2.2 From 9ef2a9a9f08722998540ed2ff38bccd0c54344c8 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Wed, 9 May 2007 15:09:12 -0700 Subject: ACPI: dock: unsuppress uevents Platform devices may not send uevents by default - override the setting so that we can send uevents on dock/undock. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 98ec717b14..4efc12cf61 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -751,6 +751,9 @@ static int dock_add(acpi_handle handle) return PTR_ERR(dock_device); } + /* we want the dock device to send uevents */ + dock_device->dev.uevent_suppress = 0; + ret = device_create_file(&dock_device->dev, &dev_attr_docked); if (ret) { printk("Error %d adding sysfs file\n", ret); -- cgit v1.2.2 From 79a8f70b4b9127eacfc91dd1436c4a7be05e62ab Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Wed, 9 May 2007 15:10:22 -0700 Subject: ACPI: dock: send envp with uevent Send an env along with our KOBJ_CHANGE uevent so that user space has the option of checking for that to see if a dock or undock has occurred. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index 4efc12cf61..dc3df93d23 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -336,11 +336,19 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event) static void dock_event(struct dock_station *ds, u32 event, int num) { struct device *dev = &dock_device->dev; + char event_string[7]; + char *envp[] = { event_string, NULL }; + + if (num == UNDOCK_EVENT) + sprintf(event_string, "UNDOCK"); + else + sprintf(event_string, "DOCK"); + /* * Indicate that the status of the dock station has * changed. */ - kobject_uevent(&dev->kobj, KOBJ_CHANGE); + kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); } /** -- cgit v1.2.2 From 1f9767df1346c9ce09d6e51b9f34b851e3d94fad Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Wed, 9 May 2007 15:55:53 -0700 Subject: ACPI: bay: unsuppress uevents Since platform devices seem to get uevents suppressed by default, manually unsuppress for the bay device since we want to be able to send uevents. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/bay.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c index fb3f31b5e6..00d3f3f17a 100644 --- a/drivers/acpi/bay.c +++ b/drivers/acpi/bay.c @@ -288,6 +288,11 @@ static int bay_add(acpi_handle handle, int id) new_bay->pdev = pdev; platform_set_drvdata(pdev, new_bay); + /* + * we want the bay driver to be able to send uevents + */ + pdev->dev.uevent_suppress = 0; + if (acpi_bay_add_fs(new_bay)) { platform_device_unregister(new_bay->pdev); goto bay_add_err; -- cgit v1.2.2 From 78490d82129f7331d1366737c8704c1c053221a3 Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Fri, 11 May 2007 13:18:55 -0400 Subject: ACPI: battery: syntax cleanup In response to review comments from Andrew Morton Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/battery.c | 418 ++++++++++++++++++++----------------------------- 1 file changed, 172 insertions(+), 246 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index b5df318978..cad932de38 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -43,9 +43,6 @@ #define ACPI_BATTERY_CLASS "battery" #define ACPI_BATTERY_HID "PNP0C0A" #define ACPI_BATTERY_DEVICE_NAME "Battery" -#define ACPI_BATTERY_FILE_INFO "info" -#define ACPI_BATTERY_FILE_STATE "state" -#define ACPI_BATTERY_FILE_ALARM "alarm" #define ACPI_BATTERY_NOTIFY_STATUS 0x80 #define ACPI_BATTERY_NOTIFY_INFO 0x81 #define ACPI_BATTERY_UNITS_WATTS "mW" @@ -111,13 +108,18 @@ struct acpi_battery_info { acpi_string oem_info; }; +enum acpi_battery_files{ + ACPI_BATTERY_INFO = 0, + ACPI_BATTERY_STATE, + ACPI_BATTERY_ALARM, + ACPI_BATTERY_NUMFILES, +}; + struct acpi_battery_flags { u8 battery_present_prev; u8 alarm_present; u8 init_update; - u8 info_update; - u8 state_update; - u8 alarm_update; + u8 update[ACPI_BATTERY_NUMFILES]; u8 power_unit; }; @@ -128,47 +130,37 @@ struct acpi_battery { struct acpi_buffer bif_data; struct acpi_buffer bst_data; unsigned long alarm; - unsigned long info_update_time; - unsigned long state_update_time; - unsigned long alarm_update_time; + unsigned long update_time[ACPI_BATTERY_NUMFILES]; }; -#define acpi_battery_present(battery) battery->device->status.battery_present -#define acpi_battery_present_prev(battery) battery->flags.battery_present_prev -#define acpi_battery_alarm_present(battery) battery->flags.alarm_present -#define acpi_battery_init_update_flag(battery) battery->flags.init_update -#define acpi_battery_info_update_flag(battery) battery->flags.info_update -#define acpi_battery_state_update_flag(battery) battery->flags.state_update -#define acpi_battery_alarm_update_flag(battery) battery->flags.alarm_update -#define acpi_battery_power_units(battery) battery->flags.power_unit ? \ - ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS -#define acpi_battery_handle(battery) battery->device->handle -#define acpi_battery_inserted(battery) (!acpi_battery_present_prev(battery) & acpi_battery_present(battery)) -#define acpi_battery_removed(battery) (acpi_battery_present_prev(battery) & !acpi_battery_present(battery)) -#define acpi_battery_bid(battery) acpi_device_bid(battery->device) -#define acpi_battery_status_str(battery) acpi_battery_present(battery) ? "present" : "absent" - -/* -------------------------------------------------------------------------- - Battery Management - -------------------------------------------------------------------------- */ - -static void acpi_battery_mutex_lock(struct acpi_battery *battery) +inline int acpi_battery_present(struct acpi_battery *battery) { - mutex_lock(&battery->mutex); + return battery->device->status.battery_present; +} +inline char *acpi_battery_power_units(struct acpi_battery *battery) +{ + if (battery->flags.power_unit) + return ACPI_BATTERY_UNITS_AMPS; + else + return ACPI_BATTERY_UNITS_WATTS; } -static void acpi_battery_mutex_unlock(struct acpi_battery *battery) +inline acpi_handle acpi_battery_handle(struct acpi_battery *battery) { - mutex_unlock(&battery->mutex); + return battery->device->handle; } +/* -------------------------------------------------------------------------- + Battery Management + -------------------------------------------------------------------------- */ + static void acpi_battery_check_result(struct acpi_battery *battery, int result) { if (!battery) return; if (result) { - acpi_battery_init_update_flag(battery) = 1; + battery->flags.init_update = 1; } } @@ -189,9 +181,7 @@ static int acpi_battery_extract_package(struct acpi_battery *battery, } if (data_null.length != data->length) { - if (data->pointer) { - kfree(data->pointer); - } + kfree(data->pointer); data->pointer = kzalloc(data_null.length, GFP_KERNEL); if (!data->pointer) { ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()")); @@ -234,12 +224,12 @@ static int acpi_battery_get_info(struct acpi_battery *battery) struct acpi_buffer *data = NULL; struct acpi_battery_info *bif = NULL; - battery->info_update_time = get_seconds(); + battery->update_time[ACPI_BATTERY_INFO] = get_seconds(); if (!acpi_battery_present(battery)) return 0; - /* Evalute _BIF */ + /* Evaluate _BIF */ status = acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL, @@ -263,9 +253,7 @@ static int acpi_battery_get_info(struct acpi_battery *battery) end: - if (buffer.pointer) { - kfree(buffer.pointer); - } + kfree(buffer.pointer); if (!result) { bif = data->pointer; @@ -286,12 +274,12 @@ static int acpi_battery_get_state(struct acpi_battery *battery) union acpi_object *package = NULL; struct acpi_buffer *data = NULL; - battery->state_update_time = get_seconds(); + battery->update_time[ACPI_BATTERY_STATE] = get_seconds(); if (!acpi_battery_present(battery)) return 0; - /* Evalute _BST */ + /* Evaluate _BST */ status = acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL, @@ -314,16 +302,14 @@ static int acpi_battery_get_state(struct acpi_battery *battery) goto end; end: - if (buffer.pointer) { - kfree(buffer.pointer); - } + kfree(buffer.pointer); return result; } static int acpi_battery_get_alarm(struct acpi_battery *battery) { - battery->alarm_update_time = get_seconds(); + battery->update_time[ACPI_BATTERY_ALARM] = get_seconds(); return 0; } @@ -335,12 +321,12 @@ static int acpi_battery_set_alarm(struct acpi_battery *battery, union acpi_object arg0 = { ACPI_TYPE_INTEGER }; struct acpi_object_list arg_list = { 1, &arg0 }; - battery->alarm_update_time = get_seconds(); + battery->update_time[ACPI_BATTERY_ALARM] = get_seconds(); if (!acpi_battery_present(battery)) return -ENODEV; - if (!acpi_battery_alarm_present(battery)) + if (!battery->flags.alarm_present) return -ENODEV; arg0.integer.value = alarm; @@ -370,7 +356,7 @@ static int acpi_battery_init_alarm(struct acpi_battery *battery) status = acpi_get_handle(acpi_battery_handle(battery), "_BTP", &handle); if (ACPI_SUCCESS(status)) { - acpi_battery_alarm_present(battery) = 1; + battery->flags.alarm_present = 1; if (!alarm && bif) { alarm = bif->design_capacity_warning; } @@ -378,7 +364,7 @@ static int acpi_battery_init_alarm(struct acpi_battery *battery) if (result) goto end; } else { - acpi_battery_alarm_present(battery) = 0; + battery->flags.alarm_present = 0; } end: @@ -394,7 +380,7 @@ static int acpi_battery_init_update(struct acpi_battery *battery) if (result) return result; - acpi_battery_present_prev(battery) = acpi_battery_present(battery); + battery->flags.battery_present_prev = acpi_battery_present(battery); if (acpi_battery_present(battery)) { result = acpi_battery_get_info(battery); @@ -420,20 +406,20 @@ static int acpi_battery_update(struct acpi_battery *battery, update = 1; } - if (acpi_battery_init_update_flag(battery)) { + if (battery->flags.init_update) { result = acpi_battery_init_update(battery); if (result) - goto end;; + goto end; update_result = ACPI_BATTERY_INIT_UPDATE; } else if (update) { result = acpi_battery_get_status(battery); if (result) - goto end;; - if (acpi_battery_inserted(battery) - || acpi_battery_removed(battery)) { + goto end; + if ((!battery->flags.battery_present_prev & acpi_battery_present(battery)) + || (battery->flags.battery_present_prev & !acpi_battery_present(battery))) { result = acpi_battery_init_update(battery); if (result) - goto end;; + goto end; update_result = ACPI_BATTERY_INIT_UPDATE; } else { update_result = ACPI_BATTERY_EASY_UPDATE; @@ -442,7 +428,7 @@ static int acpi_battery_update(struct acpi_battery *battery, end: - acpi_battery_init_update_flag(battery) = (result != 0); + battery->flags.init_update = (result != 0); *update_result_ptr = update_result; @@ -453,16 +439,19 @@ static void acpi_battery_notify_update(struct acpi_battery *battery) { acpi_battery_get_status(battery); - if (acpi_battery_init_update_flag(battery)) { + if (battery->flags.init_update) { return; } - if (acpi_battery_inserted(battery) || acpi_battery_removed(battery)) { - acpi_battery_init_update_flag(battery) = 1; + if ((!battery->flags.battery_present_prev & + acpi_battery_present(battery)) || + (battery->flags.battery_present_prev & + !acpi_battery_present(battery))) { + battery->flags.init_update = 1; } else { - acpi_battery_info_update_flag(battery) = 1; - acpi_battery_state_update_flag(battery) = 1; - acpi_battery_alarm_update_flag(battery) = 1; + battery->flags.update[ACPI_BATTERY_INFO] = 1; + battery->flags.update[ACPI_BATTERY_STATE] = 1; + battery->flags.update[ACPI_BATTERY_ALARM] = 1; } } @@ -472,7 +461,7 @@ static void acpi_battery_notify_update(struct acpi_battery *battery) static struct proc_dir_entry *acpi_battery_dir; -static int acpi_battery_read_info_print(struct seq_file *seq, int result) +static int acpi_battery_print_info(struct seq_file *seq, int result) { struct acpi_battery *battery = seq->private; struct acpi_battery_info *bif = NULL; @@ -549,49 +538,7 @@ static int acpi_battery_read_info_print(struct seq_file *seq, int result) return result; } -static int acpi_battery_read_info(struct seq_file *seq, void *offset) -{ - struct acpi_battery *battery = seq->private; - int result = 0; - int update_result = ACPI_BATTERY_NONE_UPDATE; - int update = 0; - - acpi_battery_mutex_lock(battery); - - update = (get_seconds() - battery->info_update_time >= update_time); - update = (update | acpi_battery_info_update_flag(battery)); - - result = acpi_battery_update(battery, update, &update_result); - if (result) - goto end; - - /* Battery Info (_BIF) */ - - if (update_result == ACPI_BATTERY_EASY_UPDATE) { - result = acpi_battery_get_info(battery); - if (result) - goto end; - } - - end: - - result = acpi_battery_read_info_print(seq, result); - - acpi_battery_check_result(battery, result); - - acpi_battery_info_update_flag(battery) = result; - - acpi_battery_mutex_unlock(battery); - - return result; -} - -static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) -{ - return single_open(file, acpi_battery_read_info, PDE(inode)->data); -} - -static int acpi_battery_read_state_print(struct seq_file *seq, int result) +static int acpi_battery_print_state(struct seq_file *seq, int result) { struct acpi_battery *battery = seq->private; struct acpi_battery_state *bst = NULL; @@ -661,49 +608,7 @@ static int acpi_battery_read_state_print(struct seq_file *seq, int result) return result; } -static int acpi_battery_read_state(struct seq_file *seq, void *offset) -{ - struct acpi_battery *battery = seq->private; - int result = 0; - int update_result = ACPI_BATTERY_NONE_UPDATE; - int update = 0; - - acpi_battery_mutex_lock(battery); - - update = (get_seconds() - battery->state_update_time >= update_time); - update = (update | acpi_battery_state_update_flag(battery)); - - result = acpi_battery_update(battery, update, &update_result); - if (result) - goto end; - - /* Battery State (_BST) */ - - if (update_result == ACPI_BATTERY_EASY_UPDATE) { - result = acpi_battery_get_state(battery); - if (result) - goto end; - } - - end: - - result = acpi_battery_read_state_print(seq, result); - - acpi_battery_check_result(battery, result); - - acpi_battery_state_update_flag(battery) = result; - - acpi_battery_mutex_unlock(battery); - - return result; -} - -static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) -{ - return single_open(file, acpi_battery_read_state, PDE(inode)->data); -} - -static int acpi_battery_read_alarm_print(struct seq_file *seq, int result) +static int acpi_battery_print_alarm(struct seq_file *seq, int result) { struct acpi_battery *battery = seq->private; char *units = "?"; @@ -734,43 +639,6 @@ static int acpi_battery_read_alarm_print(struct seq_file *seq, int result) return result; } -static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) -{ - struct acpi_battery *battery = seq->private; - int result = 0; - int update_result = ACPI_BATTERY_NONE_UPDATE; - int update = 0; - - acpi_battery_mutex_lock(battery); - - update = (get_seconds() - battery->alarm_update_time >= update_time); - update = (update | acpi_battery_alarm_update_flag(battery)); - - result = acpi_battery_update(battery, update, &update_result); - if (result) - goto end; - - /* Battery Alarm */ - - if (update_result == ACPI_BATTERY_EASY_UPDATE) { - result = acpi_battery_get_alarm(battery); - if (result) - goto end; - } - - end: - - result = acpi_battery_read_alarm_print(seq, result); - - acpi_battery_check_result(battery, result); - - acpi_battery_alarm_update_flag(battery) = result; - - acpi_battery_mutex_unlock(battery); - - return result; -} - static ssize_t acpi_battery_write_alarm(struct file *file, const char __user * buffer, @@ -785,7 +653,7 @@ acpi_battery_write_alarm(struct file *file, if (!battery || (count > sizeof(alarm_string) - 1)) return -EINVAL; - acpi_battery_mutex_lock(battery); + mutex_lock(&battery->mutex); result = acpi_battery_update(battery, 1, &update_result); if (result) { @@ -817,44 +685,128 @@ acpi_battery_write_alarm(struct file *file, if (!result) result = count; - acpi_battery_mutex_unlock(battery); + mutex_unlock(&battery->mutex); + + return result; +} + +typedef int(*print_func)(struct seq_file *seq, int result); +typedef int(*get_func)(struct acpi_battery *battery); + +static struct acpi_read_mux { + print_func print; + get_func get; +} acpi_read_funcs[ACPI_BATTERY_NUMFILES] = { + {.get = acpi_battery_get_info, .print = acpi_battery_print_info}, + {.get = acpi_battery_get_state, .print = acpi_battery_print_state}, + {.get = acpi_battery_get_alarm, .print = acpi_battery_print_alarm}, +}; +static int acpi_battery_read(int fid, struct seq_file *seq) +{ + struct acpi_battery *battery = seq->private; + int result = 0; + int update_result = ACPI_BATTERY_NONE_UPDATE; + int update = 0; + + mutex_lock(&battery->mutex); + + update = (get_seconds() - battery->update_time[fid] >= update_time); + update = (update | battery->flags.update[fid]); + + result = acpi_battery_update(battery, update, &update_result); + if (result) + goto end; + + if (update_result == ACPI_BATTERY_EASY_UPDATE) { + result = acpi_read_funcs[fid].get(battery); + if (result) + goto end; + } + + end: + result = acpi_read_funcs[fid].print(seq, result); + acpi_battery_check_result(battery, result); + battery->flags.update[fid] = result; + mutex_unlock(&battery->mutex); return result; } +static int acpi_battery_read_info(struct seq_file *seq, void *offset) +{ + return acpi_battery_read(ACPI_BATTERY_INFO, seq); +} + +static int acpi_battery_read_state(struct seq_file *seq, void *offset) +{ + return acpi_battery_read(ACPI_BATTERY_STATE, seq); +} + +static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) +{ + return acpi_battery_read(ACPI_BATTERY_ALARM, seq); +} + +static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_battery_read_info, PDE(inode)->data); +} + +static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) +{ + return single_open(file, acpi_battery_read_state, PDE(inode)->data); +} + static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) { return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); } -static const struct file_operations acpi_battery_info_ops = { +static struct battery_file { + struct file_operations ops; + mode_t mode; + char *name; +} acpi_battery_file[] = { + { + .name = "info", + .mode = S_IRUGO, + .ops = { .open = acpi_battery_info_open_fs, .read = seq_read, .llseek = seq_lseek, .release = single_release, .owner = THIS_MODULE, -}; - -static const struct file_operations acpi_battery_state_ops = { + }, + }, + { + .name = "state", + .mode = S_IRUGO, + .ops = { .open = acpi_battery_state_open_fs, .read = seq_read, .llseek = seq_lseek, .release = single_release, .owner = THIS_MODULE, -}; - -static const struct file_operations acpi_battery_alarm_ops = { + }, + }, + { + .name = "alarm", + .mode = S_IFREG | S_IRUGO | S_IWUSR, + .ops = { .open = acpi_battery_alarm_open_fs, .read = seq_read, .write = acpi_battery_write_alarm, .llseek = seq_lseek, .release = single_release, .owner = THIS_MODULE, + }, + }, }; static int acpi_battery_add_fs(struct acpi_device *device) { struct proc_dir_entry *entry = NULL; + int i; if (!acpi_device_dir(device)) { acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), @@ -864,38 +816,16 @@ static int acpi_battery_add_fs(struct acpi_device *device) acpi_device_dir(device)->owner = THIS_MODULE; } - /* 'info' [R] */ - entry = create_proc_entry(ACPI_BATTERY_FILE_INFO, - S_IRUGO, acpi_device_dir(device)); - if (!entry) - return -ENODEV; - else { - entry->proc_fops = &acpi_battery_info_ops; - entry->data = acpi_driver_data(device); - entry->owner = THIS_MODULE; - } - - /* 'status' [R] */ - entry = create_proc_entry(ACPI_BATTERY_FILE_STATE, - S_IRUGO, acpi_device_dir(device)); - if (!entry) - return -ENODEV; - else { - entry->proc_fops = &acpi_battery_state_ops; - entry->data = acpi_driver_data(device); - entry->owner = THIS_MODULE; - } - - /* 'alarm' [R/W] */ - entry = create_proc_entry(ACPI_BATTERY_FILE_ALARM, - S_IFREG | S_IRUGO | S_IWUSR, - acpi_device_dir(device)); - if (!entry) - return -ENODEV; - else { - entry->proc_fops = &acpi_battery_alarm_ops; - entry->data = acpi_driver_data(device); - entry->owner = THIS_MODULE; + for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { + entry = create_proc_entry(acpi_battery_file[i].name, + acpi_battery_file[i].mode, acpi_device_dir(device)); + if (!entry) + return -ENODEV; + else { + entry->proc_fops = &acpi_battery_file[i].ops; + entry->data = acpi_driver_data(device); + entry->owner = THIS_MODULE; + } } return 0; @@ -903,14 +833,12 @@ static int acpi_battery_add_fs(struct acpi_device *device) static int acpi_battery_remove_fs(struct acpi_device *device) { + int i; if (acpi_device_dir(device)) { - remove_proc_entry(ACPI_BATTERY_FILE_ALARM, - acpi_device_dir(device)); - remove_proc_entry(ACPI_BATTERY_FILE_STATE, - acpi_device_dir(device)); - remove_proc_entry(ACPI_BATTERY_FILE_INFO, + for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) { + remove_proc_entry(acpi_battery_file[i].name, acpi_device_dir(device)); - + } remove_proc_entry(acpi_device_bid(device), acpi_battery_dir); acpi_device_dir(device) = NULL; } @@ -966,7 +894,7 @@ static int acpi_battery_add(struct acpi_device *device) mutex_init(&battery->mutex); - acpi_battery_mutex_lock(battery); + mutex_lock(&battery->mutex); battery->device = device; strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); @@ -977,7 +905,7 @@ static int acpi_battery_add(struct acpi_device *device) if (result) goto end; - acpi_battery_init_update_flag(battery) = 1; + battery->flags.init_update = 1; result = acpi_battery_add_fs(device); if (result) @@ -1003,7 +931,7 @@ static int acpi_battery_add(struct acpi_device *device) kfree(battery); } - acpi_battery_mutex_unlock(battery); + mutex_unlock(&battery->mutex); return result; } @@ -1018,7 +946,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type) battery = acpi_driver_data(device); - acpi_battery_mutex_lock(battery); + mutex_lock(&battery->mutex); status = acpi_remove_notify_handler(device->handle, ACPI_ALL_NOTIFY, @@ -1026,13 +954,11 @@ static int acpi_battery_remove(struct acpi_device *device, int type) acpi_battery_remove_fs(device); - if (battery->bif_data.pointer) - kfree(battery->bif_data.pointer); + kfree(battery->bif_data.pointer); - if (battery->bst_data.pointer) - kfree(battery->bst_data.pointer); + kfree(battery->bst_data.pointer); - acpi_battery_mutex_unlock(battery); + mutex_unlock(&battery->mutex); mutex_destroy(&battery->mutex); @@ -1051,7 +977,7 @@ static int acpi_battery_resume(struct acpi_device *device) battery = device->driver_data; - acpi_battery_init_update_flag(battery) = 1; + battery->flags.init_update = 1; return 0; } -- cgit v1.2.2 From 01854e697a77a434104b2f7e6d7fd463a978af32 Mon Sep 17 00:00:00 2001 From: Luming Yu Date: Sat, 26 May 2007 22:49:58 +0800 Subject: ACPI: add ACPI 3.0 _TPC _TSS _PTC throttling support adds _TPC _TSS _PTC -- Throttling Present Capabilities Signed-off-by: Luming Yu Signed-off-by: Len Brown --- drivers/acpi/processor_core.c | 6 + drivers/acpi/processor_throttling.c | 380 +++++++++++++++++++++++++++++++++++- include/acpi/processor.h | 46 ++++- 3 files changed, 423 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index f7de02a6f4..7aefb7c0e4 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c @@ -66,6 +66,7 @@ #define ACPI_PROCESSOR_FILE_LIMIT "limit" #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 #define ACPI_PROCESSOR_NOTIFY_POWER 0x81 +#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82 #define ACPI_PROCESSOR_LIMIT_USER 0 #define ACPI_PROCESSOR_LIMIT_THERMAL 1 @@ -84,6 +85,8 @@ static int acpi_processor_info_open_fs(struct inode *inode, struct file *file); static void acpi_processor_notify(acpi_handle handle, u32 event, void *data); static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); static int acpi_processor_handle_eject(struct acpi_processor *pr); +extern int acpi_processor_tstate_has_changed(struct acpi_processor *pr); + static struct acpi_driver acpi_processor_driver = { .name = "processor", @@ -699,6 +702,9 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) acpi_processor_cst_has_changed(pr); acpi_bus_generate_event(device, event, 0); break; + case ACPI_PROCESSOR_NOTIFY_THROTTLING: + acpi_processor_tstate_has_changed(pr); + acpi_bus_generate_event(device, event, 0); default: ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unsupported event [0x%x]\n", event)); diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index b33486009f..1bae2e42a7 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c @@ -44,10 +44,222 @@ #define _COMPONENT ACPI_PROCESSOR_COMPONENT ACPI_MODULE_NAME("processor_throttling"); +static int acpi_processor_get_throttling (struct acpi_processor *pr); +int acpi_processor_set_throttling (struct acpi_processor *pr, int state); + +static int acpi_processor_get_platform_limit(struct acpi_processor *pr) +{ + acpi_status status = 0; + unsigned long tpc = 0; + + if(!pr) + return -EINVAL; + status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); + if(ACPI_FAILURE(status) && status != AE_NOT_FOUND){ + ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); + return -ENODEV; + } + pr->throttling_platform_limit = (int)tpc; + return 0; +} + +int acpi_processor_tstate_has_changed(struct acpi_processor *pr) +{ + return acpi_processor_get_platform_limit(pr); +} + +/* -------------------------------------------------------------------------- + _PTC, _TSS, _TSD support + -------------------------------------------------------------------------- */ +static int acpi_processor_get_throttling_control(struct acpi_processor *pr) +{ + int result = 0; + acpi_status status = 0; + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *ptc = NULL; + union acpi_object obj = { 0 }; + + status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer); + if (ACPI_FAILURE(status)) { + ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC")); + return -ENODEV; + } + + ptc = (union acpi_object *)buffer.pointer; + if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE) + || (ptc->package.count != 2)) { + printk(KERN_ERR PREFIX "Invalid _PTC data\n"); + result = -EFAULT; + goto end; + } + + /* + * control_register + */ + + obj = ptc->package.elements[0]; + + if ((obj.type != ACPI_TYPE_BUFFER) + || (obj.buffer.length < sizeof(struct acpi_ptc_register)) + || (obj.buffer.pointer == NULL)) { + printk(KERN_ERR PREFIX "Invalid _PTC data (control_register)\n"); + result = -EFAULT; + goto end; + } + memcpy(&pr->throttling.control_register, obj.buffer.pointer, + sizeof(struct acpi_ptc_register)); + + /* + * status_register + */ + + obj = ptc->package.elements[1]; + + if ((obj.type != ACPI_TYPE_BUFFER) + || (obj.buffer.length < sizeof(struct acpi_ptc_register)) + || (obj.buffer.pointer == NULL)) { + printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n"); + result = -EFAULT; + goto end; + } + + memcpy(&pr->throttling.status_register, obj.buffer.pointer, + sizeof(struct acpi_ptc_register)); + + end: + kfree(buffer.pointer); + + return result; +} +static int acpi_processor_get_throttling_states(struct acpi_processor *pr) +{ + int result = 0; + acpi_status status = AE_OK; + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; + struct acpi_buffer state = { 0, NULL }; + union acpi_object *tss = NULL; + int i; + + status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer); + if (ACPI_FAILURE(status)) { + ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS")); + return -ENODEV; + } + + tss = buffer.pointer; + if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) { + printk(KERN_ERR PREFIX "Invalid _TSS data\n"); + result = -EFAULT; + goto end; + } + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n", + tss->package.count)); + + pr->throttling.state_count = tss->package.count; + pr->throttling.states_tss = + kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count, + GFP_KERNEL); + if (!pr->throttling.states_tss) { + result = -ENOMEM; + goto end; + } + + for (i = 0; i < pr->throttling.state_count; i++) { + + struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]); + + state.length = sizeof(struct acpi_processor_tx_tss); + state.pointer = tx; + + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); + + status = acpi_extract_package(&(tss->package.elements[i]), + &format, &state); + if (ACPI_FAILURE(status)) { + ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data")); + result = -EFAULT; + kfree(pr->throttling.states_tss); + goto end; + } + + if (!tx->freqpercentage) { + printk(KERN_ERR PREFIX + "Invalid _TSS data: freq is zero\n"); + result = -EFAULT; + kfree(pr->throttling.states_tss); + goto end; + } + } + + end: + kfree(buffer.pointer); + + return result; +} +static int acpi_processor_get_tsd(struct acpi_processor *pr) +{ + int result = 0; + acpi_status status = AE_OK; + struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; + struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; + struct acpi_buffer state = {0, NULL}; + union acpi_object *tsd = NULL; + struct acpi_tsd_package *pdomain; + + status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); + if (ACPI_FAILURE(status)) { + return -ENODEV; + } + + tsd = buffer.pointer; + if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); + result = -EFAULT; + goto end; + } + + if (tsd->package.count != 1) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); + result = -EFAULT; + goto end; + } + + pdomain = &(pr->throttling.domain_info); + + state.length = sizeof(struct acpi_tsd_package); + state.pointer = pdomain; + + status = acpi_extract_package(&(tsd->package.elements[0]), + &format, &state); + if (ACPI_FAILURE(status)) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); + result = -EFAULT; + goto end; + } + + if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:num_entries\n")); + result = -EFAULT; + goto end; + } + + if (pdomain->revision != ACPI_TSD_REV0_REVISION) { + ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:revision\n")); + result = -EFAULT; + goto end; + } + +end: + kfree(buffer.pointer); + return result; +} + /* -------------------------------------------------------------------------- Throttling Control -------------------------------------------------------------------------- */ -static int acpi_processor_get_throttling(struct acpi_processor *pr) +static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) { int state = 0; u32 value = 0; @@ -94,7 +306,101 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr) return 0; } -int acpi_processor_set_throttling(struct acpi_processor *pr, int state) +static int acpi_read_throttling_status(struct acpi_processor_throttling *throttling) +{ + int value = -1; + switch (throttling->status_register.space_id) { + case ACPI_ADR_SPACE_SYSTEM_IO: + acpi_os_read_port((acpi_io_address)throttling->status_register.address, + &value, + (u32)throttling->status_register.bit_width*8); + break; + case ACPI_ADR_SPACE_FIXED_HARDWARE: + printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); + break; + default: + printk(KERN_ERR PREFIX "Unknown addr space %d\n", + (u32) (throttling->status_register.space_id)); + } + return value; +} + +static int acpi_write_throttling_state(struct acpi_processor_throttling *throttling,int value) +{ + int ret = -1; + + switch (throttling->control_register.space_id) { + case ACPI_ADR_SPACE_SYSTEM_IO: + acpi_os_write_port((acpi_io_address)throttling->control_register.address, + value, + (u32)throttling->control_register.bit_width*8); + ret = 0; + break; + case ACPI_ADR_SPACE_FIXED_HARDWARE: + printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); + break; + default: + printk(KERN_ERR PREFIX "Unknown addr space %d\n", + (u32) (throttling->control_register.space_id)); + } + return ret; +} + +static int acpi_get_throttling_state(struct acpi_processor *pr,int value) +{ + int i; + + for (i = 0; i < pr->throttling.state_count; i++) { + struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]); + if(tx->control == value) + break; + } + if(i > pr->throttling.state_count) + i=-1; + return i; +} + +static int acpi_get_throttling_value(struct acpi_processor *pr,int state) +{ + int value = -1; + if(state >=0 && state <= pr->throttling.state_count){ + struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[state]); + value = tx->control; + } + return value; +} + +static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) +{ + int state = 0; + u32 value = 0; + + + if (!pr) + return -EINVAL; + + if (!pr->flags.throttling) + return -ENODEV; + + pr->throttling.state = 0; + local_irq_disable(); + value = acpi_read_throttling_status(&pr->throttling); + if(value >= 0){ + state = acpi_get_throttling_state(pr,value); + pr->throttling.state = state; + } + local_irq_enable(); + + return 0; +} + + +static int acpi_processor_get_throttling(struct acpi_processor *pr) +{ + return pr->throttling.acpi_processor_get_throttling(pr); +} + +int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state) { u32 value = 0; u32 duty_mask = 0; @@ -113,6 +419,8 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state) if (state == pr->throttling.state) return 0; + if (state < pr->throttling_platform_limit) + return -EPERM; /* * Calculate the duty_value and duty_mask. */ @@ -165,11 +473,50 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state) return 0; } +int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) +{ + u32 value = 0; + + if (!pr) + return -EINVAL; + + if ((state < 0) || (state > (pr->throttling.state_count - 1))) + return -EINVAL; + + if (!pr->flags.throttling) + return -ENODEV; + + if (state == pr->throttling.state) + return 0; + + if (state < pr->throttling_platform_limit) + return -EPERM; + + local_irq_disable(); + + value = acpi_get_throttling_value(pr,state); + if(value >=0){ + acpi_write_throttling_state(&pr->throttling,value); + pr->throttling.state = state; + } + local_irq_enable(); + + return 0; +} + +int acpi_processor_set_throttling(struct acpi_processor *pr, int state) +{ + return pr->throttling.acpi_processor_set_throttling(pr,state); +} + int acpi_processor_get_throttling_info(struct acpi_processor *pr) { int result = 0; int step = 0; int i = 0; + int no_ptc = 0; + int no_tss = 0; + int no_tsd = 0; ACPI_DEBUG_PRINT((ACPI_DB_INFO, @@ -182,6 +529,17 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) return -EINVAL; /* TBD: Support ACPI 2.0 objects */ + no_ptc = acpi_processor_get_throttling_control(pr); + no_tss = acpi_processor_get_throttling_states(pr); + no_tsd = acpi_processor_get_tsd(pr); + + if(no_ptc || no_tss) { + pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_fadt; + pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_fadt; + } else { + pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_ptc; + pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_ptc; + } if (!pr->throttling.address) { ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); @@ -280,15 +638,25 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq, } seq_printf(seq, "state count: %d\n" - "active state: T%d\n", - pr->throttling.state_count, pr->throttling.state); + "active state: T%d\n" + "state available: T%d to T%d\n", + pr->throttling.state_count, pr->throttling.state, + pr->throttling_platform_limit, + pr->throttling.state_count-1); seq_puts(seq, "states:\n"); - for (i = 0; i < pr->throttling.state_count; i++) - seq_printf(seq, " %cT%d: %02d%%\n", + if(acpi_processor_get_throttling == acpi_processor_get_throttling_fadt) + for (i = 0; i < pr->throttling.state_count; i++) + seq_printf(seq, " %cT%d: %02d%%\n", (i == pr->throttling.state ? '*' : ' '), i, (pr->throttling.states[i].performance ? pr-> throttling.states[i].performance / 10 : 0)); + else + for (i = 0; i < pr->throttling.state_count; i++) + seq_printf(seq, " %cT%d: %02d%%\n", + (i == pr->throttling.state ? '*' : ' '), i, + (int)pr->throttling.states_tss[i].freqpercentage); + end: return 0; diff --git a/include/acpi/processor.h b/include/acpi/processor.h index b4b0ffdab0..01d2f24c22 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -21,6 +21,8 @@ #define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */ #define ACPI_PSD_REV0_ENTRIES 5 +#define ACPI_TSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */ +#define ACPI_TSD_REV0_ENTRIES 5 /* * Types of coordination defined in ACPI 3.0. Same macros can be used across * P, C and T states @@ -125,17 +127,52 @@ struct acpi_processor_performance { /* Throttling Control */ +struct acpi_tsd_package { + acpi_integer num_entries; + acpi_integer revision; + acpi_integer domain; + acpi_integer coord_type; + acpi_integer num_processors; +} __attribute__ ((packed)); + +struct acpi_ptc_register { + u8 descriptor; + u16 length; + u8 space_id; + u8 bit_width; + u8 bit_offset; + u8 reserved; + u64 address; +} __attribute__ ((packed)); + +struct acpi_processor_tx_tss { + acpi_integer freqpercentage; /* */ + acpi_integer power; /* milliWatts */ + acpi_integer transition_latency; /* microseconds */ + acpi_integer control; /* control value */ + acpi_integer status; /* success indicator */ +}; struct acpi_processor_tx { u16 power; u16 performance; }; +struct acpi_processor; struct acpi_processor_throttling { - int state; + unsigned int state; + unsigned int platform_limit; + struct acpi_pct_register control_register; + struct acpi_pct_register status_register; + unsigned int state_count; + struct acpi_processor_tx_tss *states_tss; + struct acpi_tsd_package domain_info; + cpumask_t shared_cpu_map; + int (*acpi_processor_get_throttling) (struct acpi_processor *pr); + int (*acpi_processor_set_throttling) (struct acpi_processor *pr, int state); + u32 address; u8 duty_offset; u8 duty_width; - int state_count; struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING]; }; @@ -169,6 +206,9 @@ struct acpi_processor { u32 id; u32 pblk; int performance_platform_limit; + int throttling_platform_limit; + /*0 - states 0..n-th satte available*/ + struct acpi_processor_flags flags; struct acpi_processor_power power; struct acpi_processor_performance *performance; @@ -270,7 +310,7 @@ static inline int acpi_processor_ppc_has_changed(struct acpi_processor *pr) /* in processor_throttling.c */ int acpi_processor_get_throttling_info(struct acpi_processor *pr); -int acpi_processor_set_throttling(struct acpi_processor *pr, int state); +extern int acpi_processor_set_throttling(struct acpi_processor *pr, int state); extern struct file_operations acpi_processor_throttling_fops; /* in processor_idle.c */ -- cgit v1.2.2 From ff55a9cebab02403f942121e2f898bb06ecfffbb Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sat, 2 Jun 2007 00:15:25 -0400 Subject: ACPI: Lindent processor throttling code Signed-off-by: Len Brown --- drivers/acpi/processor_throttling.c | 140 +++++++++++++++++++----------------- include/acpi/processor.h | 7 +- 2 files changed, 79 insertions(+), 68 deletions(-) diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index 1bae2e42a7..3a2e9a6018 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c @@ -44,18 +44,18 @@ #define _COMPONENT ACPI_PROCESSOR_COMPONENT ACPI_MODULE_NAME("processor_throttling"); -static int acpi_processor_get_throttling (struct acpi_processor *pr); -int acpi_processor_set_throttling (struct acpi_processor *pr, int state); +static int acpi_processor_get_throttling(struct acpi_processor *pr); +int acpi_processor_set_throttling(struct acpi_processor *pr, int state); static int acpi_processor_get_platform_limit(struct acpi_processor *pr) { acpi_status status = 0; unsigned long tpc = 0; - if(!pr) + if (!pr) return -EINVAL; status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); - if(ACPI_FAILURE(status) && status != AE_NOT_FOUND){ + if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); return -ENODEV; } @@ -102,7 +102,8 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) if ((obj.type != ACPI_TYPE_BUFFER) || (obj.buffer.length < sizeof(struct acpi_ptc_register)) || (obj.buffer.pointer == NULL)) { - printk(KERN_ERR PREFIX "Invalid _PTC data (control_register)\n"); + printk(KERN_ERR PREFIX + "Invalid _PTC data (control_register)\n"); result = -EFAULT; goto end; } @@ -124,9 +125,9 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) } memcpy(&pr->throttling.status_register, obj.buffer.pointer, - sizeof(struct acpi_ptc_register)); + sizeof(struct acpi_ptc_register)); - end: + end: kfree(buffer.pointer); return result; @@ -168,7 +169,9 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) for (i = 0; i < pr->throttling.state_count; i++) { - struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]); + struct acpi_processor_tx_tss *tx = + (struct acpi_processor_tx_tss *)&(pr->throttling. + states_tss[i]); state.length = sizeof(struct acpi_processor_tx_tss); state.pointer = tx; @@ -186,7 +189,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) if (!tx->freqpercentage) { printk(KERN_ERR PREFIX - "Invalid _TSS data: freq is zero\n"); + "Invalid _TSS data: freq is zero\n"); result = -EFAULT; kfree(pr->throttling.states_tss); goto end; @@ -198,14 +201,14 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) return result; } -static int acpi_processor_get_tsd(struct acpi_processor *pr) +static int acpi_processor_get_tsd(struct acpi_processor *pr) { int result = 0; acpi_status status = AE_OK; - struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; - struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; - struct acpi_buffer state = {0, NULL}; - union acpi_object *tsd = NULL; + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; + struct acpi_buffer state = { 0, NULL }; + union acpi_object *tsd = NULL; struct acpi_tsd_package *pdomain; status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); @@ -232,7 +235,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) state.pointer = pdomain; status = acpi_extract_package(&(tsd->package.elements[0]), - &format, &state); + &format, &state); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); result = -EFAULT; @@ -251,7 +254,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) goto end; } -end: + end: kfree(buffer.pointer); return result; } @@ -266,7 +269,6 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) u32 duty_mask = 0; u32 duty_value = 0; - if (!pr) return -EINVAL; @@ -306,65 +308,75 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) return 0; } -static int acpi_read_throttling_status(struct acpi_processor_throttling *throttling) +static int acpi_read_throttling_status(struct acpi_processor_throttling + *throttling) { int value = -1; switch (throttling->status_register.space_id) { case ACPI_ADR_SPACE_SYSTEM_IO: - acpi_os_read_port((acpi_io_address)throttling->status_register.address, - &value, - (u32)throttling->status_register.bit_width*8); + acpi_os_read_port((acpi_io_address) throttling->status_register. + address, &value, + (u32) throttling->status_register.bit_width * + 8); break; case ACPI_ADR_SPACE_FIXED_HARDWARE: - printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); + printk(KERN_ERR PREFIX + "HARDWARE addr space,NOT supported yet\n"); break; default: printk(KERN_ERR PREFIX "Unknown addr space %d\n", - (u32) (throttling->status_register.space_id)); + (u32) (throttling->status_register.space_id)); } return value; } -static int acpi_write_throttling_state(struct acpi_processor_throttling *throttling,int value) +static int acpi_write_throttling_state(struct acpi_processor_throttling + *throttling, int value) { int ret = -1; switch (throttling->control_register.space_id) { case ACPI_ADR_SPACE_SYSTEM_IO: - acpi_os_write_port((acpi_io_address)throttling->control_register.address, - value, - (u32)throttling->control_register.bit_width*8); + acpi_os_write_port((acpi_io_address) throttling-> + control_register.address, value, + (u32) throttling->control_register. + bit_width * 8); ret = 0; break; case ACPI_ADR_SPACE_FIXED_HARDWARE: - printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); + printk(KERN_ERR PREFIX + "HARDWARE addr space,NOT supported yet\n"); break; default: printk(KERN_ERR PREFIX "Unknown addr space %d\n", - (u32) (throttling->control_register.space_id)); + (u32) (throttling->control_register.space_id)); } return ret; } -static int acpi_get_throttling_state(struct acpi_processor *pr,int value) +static int acpi_get_throttling_state(struct acpi_processor *pr, int value) { int i; for (i = 0; i < pr->throttling.state_count; i++) { - struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]); - if(tx->control == value) + struct acpi_processor_tx_tss *tx = + (struct acpi_processor_tx_tss *)&(pr->throttling. + states_tss[i]); + if (tx->control == value) break; } - if(i > pr->throttling.state_count) - i=-1; + if (i > pr->throttling.state_count) + i = -1; return i; } -static int acpi_get_throttling_value(struct acpi_processor *pr,int state) +static int acpi_get_throttling_value(struct acpi_processor *pr, int state) { int value = -1; - if(state >=0 && state <= pr->throttling.state_count){ - struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[state]); + if (state >= 0 && state <= pr->throttling.state_count) { + struct acpi_processor_tx_tss *tx = + (struct acpi_processor_tx_tss *)&(pr->throttling. + states_tss[state]); value = tx->control; } return value; @@ -375,7 +387,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) int state = 0; u32 value = 0; - if (!pr) return -EINVAL; @@ -385,8 +396,8 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) pr->throttling.state = 0; local_irq_disable(); value = acpi_read_throttling_status(&pr->throttling); - if(value >= 0){ - state = acpi_get_throttling_state(pr,value); + if (value >= 0) { + state = acpi_get_throttling_state(pr, value); pr->throttling.state = state; } local_irq_enable(); @@ -394,7 +405,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) return 0; } - static int acpi_processor_get_throttling(struct acpi_processor *pr) { return pr->throttling.acpi_processor_get_throttling(pr); @@ -406,7 +416,6 @@ int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state) u32 duty_mask = 0; u32 duty_value = 0; - if (!pr) return -EINVAL; @@ -494,9 +503,9 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) local_irq_disable(); - value = acpi_get_throttling_value(pr,state); - if(value >=0){ - acpi_write_throttling_state(&pr->throttling,value); + value = acpi_get_throttling_value(pr, state); + if (value >= 0) { + acpi_write_throttling_state(&pr->throttling, value); pr->throttling.state = state; } local_irq_enable(); @@ -506,7 +515,7 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) int acpi_processor_set_throttling(struct acpi_processor *pr, int state) { - return pr->throttling.acpi_processor_set_throttling(pr,state); + return pr->throttling.acpi_processor_set_throttling(pr, state); } int acpi_processor_get_throttling_info(struct acpi_processor *pr) @@ -518,7 +527,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) int no_tss = 0; int no_tsd = 0; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", pr->throttling.address, @@ -533,12 +541,16 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) no_tss = acpi_processor_get_throttling_states(pr); no_tsd = acpi_processor_get_tsd(pr); - if(no_ptc || no_tss) { - pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_fadt; - pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_fadt; + if (no_ptc || no_tss) { + pr->throttling.acpi_processor_get_throttling = + &acpi_processor_get_throttling_fadt; + pr->throttling.acpi_processor_set_throttling = + &acpi_processor_set_throttling_fadt; } else { - pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_ptc; - pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_ptc; + pr->throttling.acpi_processor_get_throttling = + &acpi_processor_get_throttling_ptc; + pr->throttling.acpi_processor_set_throttling = + &acpi_processor_set_throttling_ptc; } if (!pr->throttling.address) { @@ -620,7 +632,6 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq, int i = 0; int result = 0; - if (!pr) goto end; @@ -639,24 +650,24 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq, seq_printf(seq, "state count: %d\n" "active state: T%d\n" - "state available: T%d to T%d\n", + "state available: T%d to T%d\n", pr->throttling.state_count, pr->throttling.state, - pr->throttling_platform_limit, - pr->throttling.state_count-1); + pr->throttling_platform_limit, + pr->throttling.state_count - 1); seq_puts(seq, "states:\n"); - if(acpi_processor_get_throttling == acpi_processor_get_throttling_fadt) + if (acpi_processor_get_throttling == acpi_processor_get_throttling_fadt) for (i = 0; i < pr->throttling.state_count; i++) seq_printf(seq, " %cT%d: %02d%%\n", - (i == pr->throttling.state ? '*' : ' '), i, - (pr->throttling.states[i].performance ? pr-> - throttling.states[i].performance / 10 : 0)); + (i == pr->throttling.state ? '*' : ' '), i, + (pr->throttling.states[i].performance ? pr-> + throttling.states[i].performance / 10 : 0)); else for (i = 0; i < pr->throttling.state_count; i++) seq_printf(seq, " %cT%d: %02d%%\n", - (i == pr->throttling.state ? '*' : ' '), i, - (int)pr->throttling.states_tss[i].freqpercentage); - + (i == pr->throttling.state ? '*' : ' '), i, + (int)pr->throttling.states_tss[i]. + freqpercentage); end: return 0; @@ -669,7 +680,7 @@ static int acpi_processor_throttling_open_fs(struct inode *inode, PDE(inode)->data); } -static ssize_t acpi_processor_write_throttling(struct file * file, +static ssize_t acpi_processor_write_throttling(struct file *file, const char __user * buffer, size_t count, loff_t * data) { @@ -678,7 +689,6 @@ static ssize_t acpi_processor_write_throttling(struct file * file, struct acpi_processor *pr = m->private; char state_string[12] = { '\0' }; - if (!pr || (count > sizeof(state_string) - 1)) return -EINVAL; diff --git a/include/acpi/processor.h b/include/acpi/processor.h index 01d2f24c22..f9f987f8e6 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -167,8 +167,9 @@ struct acpi_processor_throttling { struct acpi_processor_tx_tss *states_tss; struct acpi_tsd_package domain_info; cpumask_t shared_cpu_map; - int (*acpi_processor_get_throttling) (struct acpi_processor *pr); - int (*acpi_processor_set_throttling) (struct acpi_processor *pr, int state); + int (*acpi_processor_get_throttling) (struct acpi_processor * pr); + int (*acpi_processor_set_throttling) (struct acpi_processor * pr, + int state); u32 address; u8 duty_offset; @@ -207,7 +208,7 @@ struct acpi_processor { u32 pblk; int performance_platform_limit; int throttling_platform_limit; - /*0 - states 0..n-th satte available*/ + /* 0 - states 0..n-th state available */ struct acpi_processor_flags flags; struct acpi_processor_power power; -- cgit v1.2.2 From 3f8698d4d3f72252980575fb8d7b4cafeb5dd0a2 Mon Sep 17 00:00:00 2001 From: Kristen Carlson Accardi Date: Wed, 23 May 2007 14:12:29 -0700 Subject: ACPI: bay: send envp with uevent Make the bay driver send env information on bay events. Upon any bay event, we will send the string "BAY_EVENT=%d" along with the KOBJ_CHANGE, and report the event number. What the event number means will be platform specific. Event 3 is always an eject request, but an insert may be either event 1, or it may be event 0. Event 1 may also be a remove request. It would be best if you check the number of your event with udevmonitor before writing any udev scripts for inserting and removing drive bays. Signed-off-by: Kristen Carlson Accardi Cc: Stephan Berberig Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/bay.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c index 00d3f3f17a..56a5b3fffe 100644 --- a/drivers/acpi/bay.c +++ b/drivers/acpi/bay.c @@ -333,18 +333,12 @@ static void bay_notify(acpi_handle handle, u32 event, void *data) { struct bay *bay_dev = (struct bay *)data; struct device *dev = &bay_dev->pdev->dev; + char event_string[12]; + char *envp[] = { event_string, NULL }; bay_dprintk(handle, "Bay event"); - - switch(event) { - case ACPI_NOTIFY_BUS_CHECK: - case ACPI_NOTIFY_DEVICE_CHECK: - case ACPI_NOTIFY_EJECT_REQUEST: - kobject_uevent(&dev->kobj, KOBJ_CHANGE); - break; - default: - printk(KERN_ERR PREFIX "Bay: unknown event %d\n", event); - } + sprintf(event_string, "BAY_EVENT=%d\n", event); + kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp); } static acpi_status -- cgit v1.2.2 From 4d2fafd17a325b3f4f5f9edb1211bc7f4c311269 Mon Sep 17 00:00:00 2001 From: Tear Date: Wed, 23 May 2007 14:12:30 -0700 Subject: ACPI: Remove Dell Optiplex GX240 from the ACPI blacklist I have a Dell Optiplex GX240 and when I boot Linux, ACPI gets set up by only acpi=ht. dmesg shows the following line: DELL GX240 detected: force use of acpi=ht Everything seemed to be fine. However, I discovered that everything is not fine. The USB controller works so slowly that copying a few (uncached) 1 megabyte large photos from a USB-enabled digital camera takes many minutes instead of a couple of seconds. I am using Linux 2.6.21.1 on a Debian 4.0 ("Etch") system. I thought that this might be related to ACPI. So I tried to boot with _only_ "acpi=force" appended to the kernel command line. Voila, the USB controller started to work at full speed and copying photos from my digital camera took only seconds. I tested the system with "acpi=force" and could not find anything which did not work. I thought that this might be related to interrupts and APIC as well. (Note that this is APIC, not ACPI.) I tried booting with _only_ "noapic" and "nolapic" appended to the command line. Again, the USB controller started to work at full speed. Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- arch/i386/kernel/acpi/boot.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/arch/i386/kernel/acpi/boot.c b/arch/i386/kernel/acpi/boot.c index 280898b045..a2c8b9efd7 100644 --- a/arch/i386/kernel/acpi/boot.c +++ b/arch/i386/kernel/acpi/boot.c @@ -969,14 +969,6 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "PRIMERGY T850"), }, }, - { - .callback = force_acpi_ht, - .ident = "DELL GX240", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Dell Computer Corporation"), - DMI_MATCH(DMI_BOARD_NAME, "OptiPlex GX240"), - }, - }, { .callback = force_acpi_ht, .ident = "HP VISUALIZE NT Workstation", -- cgit v1.2.2 From 072971d7d3e70ddac5c5be3436d929470cc2b3fb Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sat, 9 Jun 2007 01:42:00 -0400 Subject: ACPI: disable _OSI(Linux) by default In Linux-2.6.22 we expanded the boot parameter osi= so that it can enable and !enable an OSI string. _OSI(Linux) is a special case because we know that there are both systems that require it set, and systems require that it _not_ to be set. In the long term it can't be set, for the same reason _OS(Linux) can't be enabled -- it tends to confuse BIOS that are not properly validated with Linux. Further, the semantics and version information of _OSI(Linux) were never actually defined. The kernel prints out a message if it sees _OSI(Linux) requested, and there is a DMI workaround to invoke "osi=Linux" automatically for existing systems that need it. http://bugzilla.kernel.org/show_bug.cgi?id=7787 Signed-off-by: Len Brown --- drivers/acpi/osl.c | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 58ceb18ec9..3f244eb99e 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -77,13 +77,7 @@ static struct workqueue_struct *kacpi_notify_wq; #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ static char osi_additional_string[OSI_STRING_LENGTH_MAX]; -#define OSI_LINUX_ENABLED -#ifdef OSI_LINUX_ENABLED -int osi_linux = 1; /* enable _OSI(Linux) by default */ -#else int osi_linux; /* disable _OSI(Linux) by default */ -#endif - #ifdef CONFIG_DMI static struct __initdata dmi_system_id acpi_osl_dmi_table[]; @@ -1183,17 +1177,10 @@ acpi_os_validate_interface (char *interface) if (!strcmp("Linux", interface)) { printk(KERN_WARNING PREFIX "System BIOS is requesting _OSI(Linux)\n"); -#ifdef OSI_LINUX_ENABLED - printk(KERN_WARNING PREFIX - "Please test with \"acpi_osi=!Linux\"\n" - "Please send dmidecode " - "to linux-acpi@vger.kernel.org\n"); -#else printk(KERN_WARNING PREFIX "If \"acpi_osi=Linux\" works better,\n" "Please send dmidecode " "to linux-acpi@vger.kernel.org\n"); -#endif if(osi_linux) return AE_OK; } @@ -1227,36 +1214,14 @@ acpi_os_validate_address ( } #ifdef CONFIG_DMI -#ifdef OSI_LINUX_ENABLED -static int dmi_osi_not_linux(struct dmi_system_id *d) -{ - printk(KERN_NOTICE "%s detected: requires not _OSI(Linux)\n", d->ident); - enable_osi_linux(0); - return 0; -} -#else static int dmi_osi_linux(struct dmi_system_id *d) { - printk(KERN_NOTICE "%s detected: requires _OSI(Linux)\n", d->ident); + printk(KERN_NOTICE "%s detected: enabling _OSI(Linux)\n", d->ident); enable_osi_linux(1); return 0; } -#endif static struct dmi_system_id acpi_osl_dmi_table[] __initdata = { -#ifdef OSI_LINUX_ENABLED - /* - * Boxes that need NOT _OSI(Linux) - */ - { - .callback = dmi_osi_not_linux, - .ident = "Toshiba Satellite P100", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "TOSHIBA"), - DMI_MATCH(DMI_BOARD_NAME, "Satellite P100"), - }, - }, -#else /* * Boxes that need _OSI(Linux) */ @@ -1268,7 +1233,6 @@ static struct dmi_system_id acpi_osl_dmi_table[] __initdata = { DMI_MATCH(DMI_BOARD_NAME, "MPAD-MSAE Customer Reference Boards"), }, }, -#endif {} }; #endif /* CONFIG_DMI */ -- cgit v1.2.2 From 3cdf552be228e1ca55f9c53a78f39e8b77d6159c Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Wed, 13 Jun 2007 21:24:02 -0400 Subject: ACPI: Discard invalid elements in _PSS package Make sure that the _PSS list is sorted in descending order by typical power dissipation. http://bugzilla.kernel.org/show_bug.cgi?id=7880 Signed-off-by: Zhang Rui Signed-off-by: Len Brown --- arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c index 10baa3501e..9ba2b69fc6 100644 --- a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c +++ b/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c @@ -668,8 +668,8 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) data->max_freq = perf->states[0].core_frequency * 1000; /* table init */ for (i=0; istate_count; i++) { - if (i>0 && perf->states[i].core_frequency == - perf->states[i-1].core_frequency) + if (i>0 && perf->states[i].core_frequency >= + data->freq_table[valid_states-1].frequency / 1000) continue; data->freq_table[valid_states].index = i; -- cgit v1.2.2 From e4d49531dcc2f334205d99614164ea900216b1cb Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 8 Mar 2007 17:57:31 +0100 Subject: ACPI: asus_acpi: Do not load if no device has been found asus_acpi_init() has a hack to prevent the driver from loading when asus_hotk_add() fails. However, it was returning the successful return value of acpi_bug_registger_driver() on failure. This caused an oops on unload. Instead it should return -ENODEV. Signed-off-by: Thomas Renninger Signed-off-by: Len Brown --- drivers/acpi/asus_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c index 6d7d4157e0..45360dfab2 100644 --- a/drivers/acpi/asus_acpi.c +++ b/drivers/acpi/asus_acpi.c @@ -1398,7 +1398,7 @@ static int __init asus_acpi_init(void) if (!asus_hotk_found) { acpi_bus_unregister_driver(&asus_hotk_driver); remove_proc_entry(PROC_ASUS, acpi_root_dir); - return result; + return -ENODEV; } asus_backlight_device = backlight_device_register("asus",NULL,NULL, -- cgit v1.2.2 From a4146557cdfcd1adf1a8e8c92493c2cebe1088a1 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Sat, 23 Jun 2007 15:54:36 -0400 Subject: ACPI: update MAINTAINERS for EC and battery Update ACPI Embedded Controller driver maintainer with Alexey Starikovskiy's new e-mail address at Novell/SuSE. Also, Alexey is taking over responsibility for the battery drivers. Signed-off-by: Len Brown --- MAINTAINERS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 4ce895a4b5..89b7cc6a1f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -232,15 +232,15 @@ T: git kernel.org:/pub/scm/linux/kernel/git/lenb/linux-acpi-2.6.git S: Supported ACPI BATTERY DRIVERS -P: Vladimir P. Lebedev -M: vladimir.p.lebedev@intel.com +P: Alexey Starikovskiy +M: astarikovskiy@suse.de L: linux-acpi@vger.kernel.org W: http://acpi.sourceforge.net/ S: Supported ACPI EC DRIVER P: Alexey Starikovskiy -M: alexey.y.starikovskiy@linux.intel.com +M: astarikovskiy@suse.de L: linux-acpi@vger.kernel.org W: http://acpi.sourceforge.net/ S: Supported -- cgit v1.2.2 From 5b7734b440d29dab583a6c3f0ee49ff20f323332 Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Tue, 29 May 2007 16:42:52 +0400 Subject: ACPI EC: Re-factor EC space handler to avoid using label/goto for cycle. Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/ec.c | 56 +++++++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 82f496c076..5534b23450 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -454,57 +454,35 @@ acpi_ec_space_setup(acpi_handle region_handle, } static acpi_status -acpi_ec_space_handler(u32 function, - acpi_physical_address address, - u32 bit_width, - acpi_integer * value, +acpi_ec_space_handler(u32 function, acpi_physical_address address, + u32 bits, acpi_integer *value, void *handler_context, void *region_context) { - int result = 0; struct acpi_ec *ec = handler_context; - u64 temp = *value; - acpi_integer f_v = 0; - int i = 0; + int result = 0, i = 0; + u8 temp = 0; if ((address > 0xFF) || !value || !handler_context) return AE_BAD_PARAMETER; - if (bit_width != 8 && acpi_strict) { + if (function != ACPI_READ && function != ACPI_WRITE) return AE_BAD_PARAMETER; - } - - next_byte: - switch (function) { - case ACPI_READ: - temp = 0; - result = acpi_ec_read(ec, (u8) address, (u8 *) & temp); - break; - case ACPI_WRITE: - result = acpi_ec_write(ec, (u8) address, (u8) temp); - break; - default: - result = -EINVAL; - goto out; - break; - } - bit_width -= 8; - if (bit_width) { - if (function == ACPI_READ) - f_v |= temp << 8 * i; - if (function == ACPI_WRITE) - temp >>= 8; - i++; - address++; - goto next_byte; - } + if (bits != 8 && acpi_strict) + return AE_BAD_PARAMETER; - if (function == ACPI_READ) { - f_v |= temp << 8 * i; - *value = f_v; + while (bits - i > 0) { + if (function == ACPI_READ) { + result = acpi_ec_read(ec, address, &temp); + (*value) |= ((acpi_integer)temp) << i; + } else { + temp = 0xff & ((*value) >> i); + result = acpi_ec_write(ec, address, temp); + } + i += 8; + ++address; } - out: switch (result) { case -EINVAL: return AE_BAD_PARAMETER; -- cgit v1.2.2 From 4350933a7447591041b51157a6b307be1816415f Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Tue, 29 May 2007 16:42:57 +0400 Subject: ACPI EC: drop usage of ACPI_DEBUG_PRINT as too heavy weight Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/ec.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 5534b23450..ffb8361bc1 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -39,20 +39,19 @@ #include #include -#define _COMPONENT ACPI_EC_COMPONENT -ACPI_MODULE_NAME("ec"); -#define ACPI_EC_COMPONENT 0x00100000 #define ACPI_EC_CLASS "embedded_controller" #define ACPI_EC_HID "PNP0C09" #define ACPI_EC_DEVICE_NAME "Embedded Controller" #define ACPI_EC_FILE_INFO "info" #undef PREFIX #define PREFIX "ACPI: EC: " + /* EC status register */ #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ #define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ #define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ #define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ + /* EC commands */ enum ec_command { ACPI_EC_COMMAND_READ = 0x80, @@ -245,7 +244,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0); if (status) { - printk(KERN_DEBUG PREFIX + printk(KERN_ERR PREFIX "input buffer is not empty, aborting transaction\n"); goto end; } @@ -630,10 +629,6 @@ static int acpi_ec_add(struct acpi_device *device) acpi_ec_add_fs(device); - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", - acpi_device_name(device), acpi_device_bid(device), - (u32) ec->gpe)); - return 0; } @@ -718,9 +713,6 @@ static int acpi_ec_start(struct acpi_device *device) if (!ec) return -EINVAL; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx", - ec->gpe, ec->command_addr, ec->data_addr)); - /* Boot EC is already working */ if (ec == boot_ec) return 0; @@ -779,8 +771,8 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) ec->handle = handle; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx", - ec->gpe, ec->command_addr, ec->data_addr)); + printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx", + ec->gpe, ec->command_addr, ec->data_addr); return AE_CTRL_TERMINATE; } @@ -803,7 +795,7 @@ int __init acpi_ec_ecdt_probe(void) if (ACPI_FAILURE(status)) goto error; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT")); + printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n"); boot_ec->command_addr = ecdt_ptr->control.address; boot_ec->data_addr = ecdt_ptr->data.address; -- cgit v1.2.2 From 837012ede14a8fc088be3682c964da7fc6af026b Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Tue, 29 May 2007 16:43:02 +0400 Subject: ACPI EC: Add support for non-AML EC query handlers Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/ec.c | 175 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 125 insertions(+), 50 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index ffb8361bc1..10e851021e 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #define ACPI_EC_HID "PNP0C09" #define ACPI_EC_DEVICE_NAME "Embedded Controller" #define ACPI_EC_FILE_INFO "info" + #undef PREFIX #define PREFIX "ACPI: EC: " @@ -60,6 +62,7 @@ enum ec_command { ACPI_EC_BURST_DISABLE = 0x83, ACPI_EC_COMMAND_QUERY = 0x84, }; + /* EC events */ enum ec_event { ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ @@ -93,6 +96,16 @@ static struct acpi_driver acpi_ec_driver = { /* If we find an EC via the ECDT, we need to keep a ptr to its context */ /* External interfaces use first EC only, so remember */ +typedef int (*acpi_ec_query_func) (void *data); + +struct acpi_ec_query_handler { + struct list_head node; + acpi_ec_query_func func; + acpi_handle handle; + void *data; + u8 query_bit; +}; + static struct acpi_ec { acpi_handle handle; unsigned long gpe; @@ -103,6 +116,7 @@ static struct acpi_ec { atomic_t query_pending; atomic_t event_count; wait_queue_head_t wait; + struct list_head list; } *boot_ec, *first_ec; /* -------------------------------------------------------------------------- @@ -393,21 +407,67 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data) /* -------------------------------------------------------------------------- Event Management -------------------------------------------------------------------------- */ +int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, + acpi_handle handle, acpi_ec_query_func func, + void *data) +{ + struct acpi_ec_query_handler *handler = + kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL); + if (!handler) + return -ENOMEM; + + handler->query_bit = query_bit; + handler->handle = handle; + handler->func = func; + handler->data = data; + mutex_lock(&ec->lock); + list_add_tail(&handler->node, &ec->list); + mutex_unlock(&ec->lock); + return 0; +} + +EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler); + +void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) +{ + struct acpi_ec_query_handler *handler; + mutex_lock(&ec->lock); + list_for_each_entry(handler, &ec->list, node) { + if (query_bit == handler->query_bit) { + list_del(&handler->node); + kfree(handler); + break; + } + } + mutex_unlock(&ec->lock); +} + +EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler); static void acpi_ec_gpe_query(void *ec_cxt) { struct acpi_ec *ec = ec_cxt; u8 value = 0; - char object_name[8]; + struct acpi_ec_query_handler *handler, copy; if (!ec || acpi_ec_query(ec, &value)) return; - - snprintf(object_name, 8, "_Q%2.2X", value); - - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name)); - - acpi_evaluate_object(ec->handle, object_name, NULL, NULL); + mutex_lock(&ec->lock); + list_for_each_entry(handler, &ec->list, node) { + if (value == handler->query_bit) { + /* have custom handler for this bit */ + memcpy(©, handler, sizeof(copy)); + mutex_unlock(&ec->lock); + if (copy.func) { + copy.func(copy.data); + } else if (copy.handle) { + acpi_evaluate_object(copy.handle, NULL, NULL, NULL); + } + return; + } + } + mutex_unlock(&ec->lock); + printk(KERN_ERR PREFIX "Handler for query 0x%x is not found!\n", value); } static u32 acpi_ec_gpe_handler(void *data) @@ -426,8 +486,7 @@ static u32 acpi_ec_gpe_handler(void *data) if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) { atomic_set(&ec->query_pending, 1); status = - acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, - ec); + acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec); } return status == AE_OK ? @@ -574,9 +633,6 @@ static int acpi_ec_remove_fs(struct acpi_device *device) static acpi_status ec_parse_io_ports(struct acpi_resource *resource, void *context); -static acpi_status -ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval); - static struct acpi_ec *make_acpi_ec(void) { struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); @@ -587,13 +643,52 @@ static struct acpi_ec *make_acpi_ec(void) atomic_set(&ec->event_count, 1); mutex_init(&ec->lock); init_waitqueue_head(&ec->wait); + INIT_LIST_HEAD(&ec->list); return ec; } +static acpi_status +acpi_ec_register_query_methods(acpi_handle handle, u32 level, + void *context, void **return_value) +{ + struct acpi_namespace_node *node = handle; + struct acpi_ec *ec = context; + int value = 0; + if (sscanf(node->name.ascii, "_Q%x", &value) == 1) { + acpi_ec_add_query_handler(ec, value, handle, NULL, NULL); + } + return AE_OK; +} + +static int ec_parse_device(struct acpi_ec *ec, acpi_handle handle) +{ + if (ACPI_FAILURE(acpi_walk_resources(handle, METHOD_NAME__CRS, + ec_parse_io_ports, ec))) + return -EINVAL; + + /* Get GPE bit assignment (EC events). */ + /* TODO: Add support for _GPE returning a package */ + if (ACPI_FAILURE(acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe))) + return -EINVAL; + + /* Use the global lock for all EC transactions? */ + acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); + + /* Find and register all query methods */ + acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1, + acpi_ec_register_query_methods, ec, NULL); + + ec->handle = handle; + + printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx", + ec->gpe, ec->command_addr, ec->data_addr); + + return 0; +} + static int acpi_ec_add(struct acpi_device *device) { - acpi_status status = AE_OK; struct acpi_ec *ec = NULL; if (!device) @@ -606,8 +701,7 @@ static int acpi_ec_add(struct acpi_device *device) if (!ec) return -ENOMEM; - status = ec_parse_device(device->handle, 0, ec, NULL); - if (status != AE_CTRL_TERMINATE) { + if (ec_parse_device(ec, device->handle)) { kfree(ec); return -EINVAL; } @@ -618,6 +712,8 @@ static int acpi_ec_add(struct acpi_device *device) /* We might have incorrect info for GL at boot time */ mutex_lock(&boot_ec->lock); boot_ec->global_lock = ec->global_lock; + /* Copy handlers from new ec into boot ec */ + list_splice(&ec->list, &boot_ec->list); mutex_unlock(&boot_ec->lock); kfree(ec); ec = boot_ec; @@ -628,18 +724,24 @@ static int acpi_ec_add(struct acpi_device *device) acpi_driver_data(device) = ec; acpi_ec_add_fs(device); - return 0; } static int acpi_ec_remove(struct acpi_device *device, int type) { struct acpi_ec *ec; + struct acpi_ec_query_handler *handler; if (!device) return -EINVAL; ec = acpi_driver_data(device); + mutex_lock(&ec->lock); + list_for_each_entry(handler, &ec->list, node) { + list_del(&handler->node); + kfree(handler); + } + mutex_unlock(&ec->lock); acpi_ec_remove_fs(device); acpi_driver_data(device) = NULL; if (ec == first_ec) @@ -695,15 +797,13 @@ static int ec_install_handlers(struct acpi_ec *ec) return -ENODEV; } - /* EC is fully operational, allow queries */ - atomic_set(&ec->query_pending, 0); - return 0; } static int acpi_ec_start(struct acpi_device *device) { struct acpi_ec *ec; + int ret = 0; if (!device) return -EINVAL; @@ -714,10 +814,13 @@ static int acpi_ec_start(struct acpi_device *device) return -EINVAL; /* Boot EC is already working */ - if (ec == boot_ec) - return 0; + if (ec != boot_ec) + ret = ec_install_handlers(ec); + + /* EC is fully operational, allow queries */ + atomic_set(&ec->query_pending, 0); - return ec_install_handlers(ec); + return ret; } static int acpi_ec_stop(struct acpi_device *device, int type) @@ -749,34 +852,6 @@ static int acpi_ec_stop(struct acpi_device *device, int type) return 0; } -static acpi_status -ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) -{ - acpi_status status; - - struct acpi_ec *ec = context; - status = acpi_walk_resources(handle, METHOD_NAME__CRS, - ec_parse_io_ports, ec); - if (ACPI_FAILURE(status)) - return status; - - /* Get GPE bit assignment (EC events). */ - /* TODO: Add support for _GPE returning a package */ - status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); - if (ACPI_FAILURE(status)) - return status; - - /* Use the global lock for all EC transactions? */ - acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); - - ec->handle = handle; - - printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx", - ec->gpe, ec->command_addr, ec->data_addr); - - return AE_CTRL_TERMINATE; -} - int __init acpi_ec_ecdt_probe(void) { int ret; -- cgit v1.2.2 From addad45494cb4f9c03470a4e5155f442791b0d7f Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Sat, 23 Jun 2007 16:24:48 -0400 Subject: ACPI: sbs: probe smart battery vis SMBus controller http://bugzilla.kernel.org/show_bug.cgi?id=8559 Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/sbs.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index c1bae10683..974d00ccfe 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c @@ -127,7 +127,7 @@ static int acpi_sbs_resume(struct acpi_device *device); static struct acpi_driver acpi_sbs_driver = { .name = "sbs", .class = ACPI_SBS_CLASS, - .ids = ACPI_SBS_HID, + .ids = "ACPI0001,ACPI0005", .ops = { .add = acpi_sbs_add, .remove = acpi_sbs_remove, @@ -176,10 +176,8 @@ struct acpi_battery { }; struct acpi_sbs { - acpi_handle handle; int base; struct acpi_device *device; - struct acpi_ec_smbus *smbus; struct mutex mutex; int sbsm_present; int sbsm_batteries_supported; @@ -511,7 +509,7 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs) "acpi_sbs_read_word() failed")); goto end; } - + sbs->sbsm_present = 1; sbs->sbsm_batteries_supported = battery_system_info & 0x000f; end: @@ -1630,13 +1628,12 @@ static int acpi_sbs_add(struct acpi_device *device) { struct acpi_sbs *sbs = NULL; int result = 0, remove_result = 0; - unsigned long sbs_obj; int id; acpi_status status = AE_OK; unsigned long val; status = - acpi_evaluate_integer(device->parent->handle, "_EC", NULL, &val); + acpi_evaluate_integer(device->handle, "_EC", NULL, &val); if (ACPI_FAILURE(status)) { ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Error obtaining _EC")); return -EIO; @@ -1653,7 +1650,7 @@ static int acpi_sbs_add(struct acpi_device *device) sbs_mutex_lock(sbs); - sbs->base = (val & 0xff00ull) >> 8; + sbs->base = 0xff & (val >> 8); sbs->device = device; strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); @@ -1665,24 +1662,10 @@ static int acpi_sbs_add(struct acpi_device *device) ACPI_EXCEPTION((AE_INFO, AE_ERROR, "acpi_ac_add() failed")); goto end; } - status = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj); - if (status) { - ACPI_EXCEPTION((AE_INFO, status, - "acpi_evaluate_integer() failed")); - result = -EIO; - goto end; - } - if (sbs_obj > 0) { - result = acpi_sbsm_get_info(sbs); - if (result) { - ACPI_EXCEPTION((AE_INFO, AE_ERROR, - "acpi_sbsm_get_info() failed")); - goto end; - } - sbs->sbsm_present = 1; - } - if (sbs->sbsm_present == 0) { + acpi_sbsm_get_info(sbs); + + if (!sbs->sbsm_present) { result = acpi_battery_add(sbs, 0); if (result) { ACPI_EXCEPTION((AE_INFO, AE_ERROR, @@ -1702,8 +1685,6 @@ static int acpi_sbs_add(struct acpi_device *device) } } - sbs->handle = device->handle; - init_timer(&sbs->update_timer); result = acpi_check_update_proc(sbs); if (result) -- cgit v1.2.2 From 6c5cf8aa5849819958311644ffaf8467e9fcf07e Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Tue, 3 Jul 2007 00:53:12 -0400 Subject: ACPI: static make 2 needlessly global functions static. Signed-off-by: Adrian Bunk Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/processor_throttling.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index 3a2e9a6018..3f55d1f90c 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c @@ -410,7 +410,8 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr) return pr->throttling.acpi_processor_get_throttling(pr); } -int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state) +static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, + int state) { u32 value = 0; u32 duty_mask = 0; @@ -482,7 +483,8 @@ int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state) return 0; } -int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) +static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, + int state) { u32 value = 0; -- cgit v1.2.2 From 3312111d1bd1a409892031f7979c57a52b01185c Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Tue, 3 Jul 2007 00:56:05 -0400 Subject: ACPI: static make the needlessly global osi_linux static. Signed-off-by: Adrian Bunk Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/osl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c index 3f244eb99e..5cfb7b5cc0 100644 --- a/drivers/acpi/osl.c +++ b/drivers/acpi/osl.c @@ -77,7 +77,7 @@ static struct workqueue_struct *kacpi_notify_wq; #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ static char osi_additional_string[OSI_STRING_LENGTH_MAX]; -int osi_linux; /* disable _OSI(Linux) by default */ +static int osi_linux; /* disable _OSI(Linux) by default */ #ifdef CONFIG_DMI static struct __initdata dmi_system_id acpi_osl_dmi_table[]; -- cgit v1.2.2 From 1c1558ec50618c4a179e0684037d9f7bb0c1a326 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 3 Jul 2007 01:28:49 -0400 Subject: ACPI: delete cmdline documentation for deleted hotkey code This looks like left over text in the kernel parameters documentation. Signed-off-by: Stephen Hemminger Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- Documentation/kernel-parameters.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index ce91560229..7ce5ea949d 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -220,11 +220,6 @@ and is between 256 and 4096 characters. It is defined in the file acpi_fake_ecdt [HW,ACPI] Workaround failure due to BIOS lacking ECDT - acpi_generic_hotkey [HW,ACPI] - Allow consolidated generic hotkey driver to - override platform specific driver. - See also Documentation/acpi-hotkey.txt. - acpi_pm_good [IA-32,X86-64] Override the pmtimer bug detection: force the kernel to assume that this machine's pmtimer latches its value -- cgit v1.2.2 From f70ac0e9651aa8c07dffe72a44872f92054d42c3 Mon Sep 17 00:00:00 2001 From: Danny Kukawka Date: Tue, 3 Jul 2007 01:33:53 -0400 Subject: ACPI video: Don't export sysfs backlight interface if query _BCL fail Currently the acpi video module export the backlight interface to sysfs also if acpi_video_device_lcd_query_levels() fails to read _BLC method (e.g. because the method is not available). In this case the userspace don't know which brightness level are supported and can't set a brightness level (echo return with: "write error: Invalid Argument"). This happend e.g. on a ASUS RF1 (correct supported by the asus-laptop module). The video module should not export the backlight interface if query _BLC fail, because you can't set anything from userspace and this make it useless. http://bugzilla.kernel.org/show_bug.cgi?id=8375 Signed-off-by: Danny Kukawka Acked-by: Luming Yu Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/video.c | 80 +++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index 39273dae70..5f014d3764 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c @@ -559,7 +559,6 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) static void acpi_video_device_find_cap(struct acpi_video_device *device) { - acpi_integer status; acpi_handle h_dummy1; int i; u32 max_level = 0; @@ -593,50 +592,55 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device) device->cap._DSS = 1; } - status = acpi_video_device_lcd_query_levels(device, &obj); - - if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) { - int count = 0; - union acpi_object *o; - - br = kzalloc(sizeof(*br), GFP_KERNEL); - if (!br) { - printk(KERN_ERR "can't allocate memory\n"); - } else { - br->levels = kmalloc(obj->package.count * - sizeof *(br->levels), GFP_KERNEL); - if (!br->levels) - goto out; - - for (i = 0; i < obj->package.count; i++) { - o = (union acpi_object *)&obj->package. - elements[i]; - if (o->type != ACPI_TYPE_INTEGER) { - printk(KERN_ERR PREFIX "Invalid data\n"); - continue; - } - br->levels[count] = (u32) o->integer.value; - if (br->levels[count] > max_level) - max_level = br->levels[count]; - count++; - } - out: - if (count < 2) { - kfree(br->levels); - kfree(br); + if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) { + + if (obj->package.count >= 2) { + int count = 0; + union acpi_object *o; + + br = kzalloc(sizeof(*br), GFP_KERNEL); + if (!br) { + printk(KERN_ERR "can't allocate memory\n"); } else { - br->count = count; - device->brightness = br; - ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "found %d brightness levels\n", - count)); + br->levels = kmalloc(obj->package.count * + sizeof *(br->levels), GFP_KERNEL); + if (!br->levels) + goto out; + + for (i = 0; i < obj->package.count; i++) { + o = (union acpi_object *)&obj->package. + elements[i]; + if (o->type != ACPI_TYPE_INTEGER) { + printk(KERN_ERR PREFIX "Invalid data\n"); + continue; + } + br->levels[count] = (u32) o->integer.value; + + if (br->levels[count] > max_level) + max_level = br->levels[count]; + count++; + } + out: + if (count < 2) { + kfree(br->levels); + kfree(br); + } else { + br->count = count; + device->brightness = br; + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "found %d brightness levels\n", + count)); + } } } + + } else { + ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n")); } kfree(obj); - if (device->cap._BCL && device->cap._BCM && device->cap._BQC){ + if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){ unsigned long tmp; static int count = 0; char *name; -- cgit v1.2.2 From 3f2c48c9b48423d1411695da066d525cca2a27db Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 3 Jul 2007 01:40:59 -0400 Subject: ACPI: Use menuconfig objects Use menuconfigs instead of menus, so the whole menu can be disabled at once instead of going through all options. Signed-off-by: Jan Engelhardt Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/Kconfig | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 139f41f033..a02e2f5821 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -2,16 +2,12 @@ # ACPI Configuration # -menu "ACPI (Advanced Configuration and Power Interface) Support" +menuconfig ACPI + bool "ACPI Support (Advanced Configuration and Power Interface) Support" depends on !X86_NUMAQ depends on !X86_VISWS depends on !IA64_HP_SIM depends on IA64 || X86 - depends on PM - -config ACPI - bool "ACPI Support" - depends on IA64 || X86 depends on PCI depends on PM select PNP @@ -49,7 +45,6 @@ if ACPI config ACPI_SLEEP bool "Sleep States" depends on X86 && (!SMP || SUSPEND_SMP) - depends on PM default y ---help--- This option adds support for ACPI suspend states. @@ -82,7 +77,6 @@ config ACPI_SLEEP_PROC_SLEEP config ACPI_PROCFS bool "Procfs interface (deprecated)" - depends on ACPI default y ---help--- The Procfs interface for ACPI is made optional for backward compatibility. @@ -330,7 +324,6 @@ config ACPI_CONTAINER config ACPI_HOTPLUG_MEMORY tristate "Memory Hotplug" - depends on ACPI depends on MEMORY_HOTPLUG default n help @@ -359,5 +352,3 @@ config ACPI_SBS to today's ACPI "Control Method" battery. endif # ACPI - -endmenu -- cgit v1.2.2 From 33ce2033433195ccc1fbad00d26ad854b2ab68d0 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Tue, 3 Jul 2007 01:45:44 -0400 Subject: ACPI: suspend: delete toshiba S1 quirk If we have quirk "init... after standby", we should not be calling it while resuming from hibernation. And... that quirk is only ever needed on toshiba 4030cdt... and... noone should be using standby these days, anyway. That quirk was certainly _not_ meant to be ran after hibernation. Signed-off-by: Pavel Machek Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/sleep/main.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c index bc7e16ec83..56afb1c1a4 100644 --- a/drivers/acpi/sleep/main.c +++ b/drivers/acpi/sleep/main.c @@ -210,11 +210,6 @@ static void acpi_hibernation_finish(void) /* reset firmware waking vector */ acpi_set_firmware_waking_vector((acpi_physical_address) 0); - - if (init_8259A_after_S1) { - printk("Broken toshiba laptop -> kicking interrupts\n"); - init_8259A(0); - } } static struct hibernation_ops acpi_hibernation_ops = { -- cgit v1.2.2 From 3c6394c5bd04e31d40d007af8b6c2484a08838d0 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Mon, 26 Mar 2007 22:10:34 -0400 Subject: ACPICA: Update _OSI string list Latest update for the Windows strings, with comments. Removed unused strings. Signed-off-by: Bob Moore Signed-off-by: Len Brown --- drivers/acpi/utilities/uteval.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c index 8ec6f8e481..f112af433e 100644 --- a/drivers/acpi/utilities/uteval.c +++ b/drivers/acpi/utilities/uteval.c @@ -62,16 +62,13 @@ acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc, static char *acpi_interfaces_supported[] = { /* Operating System Vendor Strings */ - "Windows 2000", - "Windows 2001", - "Windows 2001 SP0", - "Windows 2001 SP1", - "Windows 2001 SP2", - "Windows 2001 SP3", - "Windows 2001 SP4", - "Windows 2001.1", - "Windows 2001.1 SP1", /* Added 03/2006 */ - "Windows 2006", /* Added 03/2006 */ + "Windows 2000", /* Windows 2000 */ + "Windows 2001", /* Windows XP */ + "Windows 2001 SP1", /* Windows XP SP1 */ + "Windows 2001 SP2", /* Windows XP SP2 */ + "Windows 2001.1", /* Windows Server 2003 */ + "Windows 2001.1 SP1", /* Windows Server 2003 SP1 - Added 03/2006 */ + "Windows 2006", /* Windows Vista - Added 03/2006 */ /* Feature Group Strings */ -- cgit v1.2.2 From a0a3f6c69b45dcafefdce5dbac2221c02aaae871 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Tue, 27 Mar 2007 20:25:46 -0400 Subject: ACPICA: Changes for Cygwin compatibility Allow generation of ACPICA apps on Cygwin. Signed-off-by: Bob Moore Signed-off-by: Len Brown --- include/acpi/platform/acenv.h | 2 +- include/acpi/platform/aclinux.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/acpi/platform/acenv.h b/include/acpi/platform/acenv.h index dab2ec59a3..c785485e62 100644 --- a/include/acpi/platform/acenv.h +++ b/include/acpi/platform/acenv.h @@ -136,7 +136,7 @@ /*! [Begin] no source code translation */ -#if defined(__linux__) +#if defined(_LINUX) || defined(__linux__) #include "aclinux.h" #elif defined(_AED_EFI) diff --git a/include/acpi/platform/aclinux.h b/include/acpi/platform/aclinux.h index a568717f98..6ed15a0978 100644 --- a/include/acpi/platform/aclinux.h +++ b/include/acpi/platform/aclinux.h @@ -91,7 +91,10 @@ #define ACPI_USE_NATIVE_DIVIDE #endif +#ifndef __cdecl #define __cdecl +#endif + #define ACPI_FLUSH_CPU_CACHE() #endif /* __KERNEL__ */ -- cgit v1.2.2 From e0b91050f208ab370fac9269f8e42bc746889422 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Tue, 3 Apr 2007 20:00:29 -0400 Subject: ACPICA: Fixed possible corruption of global GPE list Fixed a problem in acpi_ev_delete_gpe_xrupt where the global interrupt list could be corrupted if the interrupt being removed was at the head of the list. Reported by Linn Crosetto. Signed-off-by: Bob Moore Signed-off-by: Len Brown --- drivers/acpi/events/evgpeblk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c index 902c287b3a..361ebe6c4a 100644 --- a/drivers/acpi/events/evgpeblk.c +++ b/drivers/acpi/events/evgpeblk.c @@ -586,6 +586,10 @@ acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt) flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); if (gpe_xrupt->previous) { gpe_xrupt->previous->next = gpe_xrupt->next; + } else { + /* No previous, update list head */ + + acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next; } if (gpe_xrupt->next) { -- cgit v1.2.2 From 55f8f3cc4f7c47c7896e2ad08e29eccc292c0c68 Mon Sep 17 00:00:00 2001 From: Bob Moore Date: Wed, 2 May 2007 15:51:37 -0400 Subject: ACPICA: Clear reserved fields for incoming ACPI 1.0 FADTs Fixed a problem with the internal FADT conversion where ACPI 1.0 FADTs that contained invalid non-zero values in reserved fields could cause later failures because these fields have meaning in later revisions of the FADT. For incoming ACPI 1.0 FADTs, these fields are now always zeroed. (Preferred_PM_Profile, PSTATE_CNT, CST_CNT, IAPC_BOOT_FLAGS.) Signed-off-by: Bob Moore Signed-off-by: Len Brown --- drivers/acpi/tables/tbfadt.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c index 1285e91474..002bb33003 100644 --- a/drivers/acpi/tables/tbfadt.c +++ b/drivers/acpi/tables/tbfadt.c @@ -211,14 +211,17 @@ void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags) * DESCRIPTION: Get a local copy of the FADT and convert it to a common format. * Performs validation on some important FADT fields. * + * NOTE: We create a local copy of the FADT regardless of the version. + * ******************************************************************************/ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length) { /* - * Check if the FADT is larger than what we know about (ACPI 2.0 version). - * Truncate the table, but make some noise. + * Check if the FADT is larger than the largest table that we expect + * (the ACPI 2.0/3.0 version). If so, truncate the table, and issue + * a warning. */ if (length > sizeof(struct acpi_table_fadt)) { ACPI_WARNING((AE_INFO, @@ -227,10 +230,12 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length) sizeof(struct acpi_table_fadt))); } - /* Copy the entire FADT locally. Zero first for tb_convert_fadt */ + /* Clear the entire local FADT */ ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt)); + /* Copy the original FADT, up to sizeof (struct acpi_table_fadt) */ + ACPI_MEMCPY(&acpi_gbl_FADT, table, ACPI_MIN(length, sizeof(struct acpi_table_fadt))); @@ -251,7 +256,7 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length) * RETURN: None * * DESCRIPTION: Converts all versions of the FADT to a common internal format. - * -> Expand all 32-bit addresses to 64-bit. + * Expand all 32-bit addresses to 64-bit. * * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), * and must contain a copy of the actual FADT. @@ -292,8 +297,23 @@ static void acpi_tb_convert_fadt(void) } /* - * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address - * structures as necessary. + * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which + * should be zero are indeed zero. This will workaround BIOSs that + * inadvertently place values in these fields. + * + * The ACPI 1.0 reserved fields that will be zeroed are the bytes located at + * offset 45, 55, 95, and the word located at offset 109, 110. + */ + if (acpi_gbl_FADT.header.revision < 3) { + acpi_gbl_FADT.preferred_profile = 0; + acpi_gbl_FADT.pstate_control = 0; + acpi_gbl_FADT.cst_control = 0; + acpi_gbl_FADT.boot_flags = 0; + } + + /* + * Expand the ACPI 1.0 32-bit V1.0 addresses to the ACPI 2.0 64-bit "X" + * generic address structures as necessary. */ for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) { target = @@ -349,18 +369,6 @@ static void acpi_tb_convert_fadt(void) acpi_gbl_FADT.xpm1a_event_block.space_id; } - - /* - * For ACPI 1.0 FADTs, ensure that reserved fields (which should be zero) - * are indeed zero. This will workaround BIOSs that inadvertently placed - * values in these fields. - */ - if (acpi_gbl_FADT.header.revision < 3) { - acpi_gbl_FADT.preferred_profile = 0; - acpi_gbl_FADT.pstate_control = 0; - acpi_gbl_FADT.cst_control = 0; - acpi_gbl_FADT.boot_flags = 0; - } } /****************************************************************************** -- cgit v1.2.2 From 864bdfb912e372670b5b2541dac9d273a4a7722a Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Tue, 19 Jun 2007 11:40:03 +0800 Subject: ACPI: Export events via generic netlink Upon ACPI events, send an "acpi_event" via Generic Netlink. This is in addition to /proc/acpi/event, which remains intact for now. Thanks to Jamal for his great help. Signed-off-by: Zhang Rui Signed-off-by: Len Brown --- drivers/acpi/bus.c | 4 ++ drivers/acpi/event.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++-- include/acpi/acpi_bus.h | 3 +- 3 files changed, 165 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index e5084ececb..6b2658c962 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -292,6 +292,10 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data) if (!device) return -EINVAL; + if (acpi_bus_generate_genetlink_event(device, type, data)) + printk(KERN_WARNING PREFIX + "Failed to generate an ACPI event via genetlink!\n"); + /* drop event on the floor if no one's listening */ if (!event_is_open) return 0; diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c index 3b23562e6f..98627b02f5 100644 --- a/drivers/acpi/event.c +++ b/drivers/acpi/event.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #define _COMPONENT ACPI_SYSTEM_COMPONENT ACPI_MODULE_NAME("event"); @@ -48,7 +50,6 @@ acpi_system_read_event(struct file *file, char __user * buffer, size_t count, static int chars_remaining = 0; static char *ptr; - if (!chars_remaining) { memset(&event, 0, sizeof(struct acpi_bus_event)); @@ -106,23 +107,174 @@ static const struct file_operations acpi_system_event_ops = { .poll = acpi_system_poll_event, }; +#ifdef CONFIG_NET +unsigned int acpi_event_seqnum; +struct acpi_genl_event { + acpi_device_class device_class; + char bus_id[15]; + u32 type; + u32 data; +}; + +/* attributes of acpi_genl_family */ +enum { + ACPI_GENL_ATTR_UNSPEC, + ACPI_GENL_ATTR_EVENT, /* ACPI event info needed by user space */ + __ACPI_GENL_ATTR_MAX, +}; +#define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1) + +/* commands supported by the acpi_genl_family */ +enum { + ACPI_GENL_CMD_UNSPEC, + ACPI_GENL_CMD_EVENT, /* kernel->user notifications for ACPI events */ + __ACPI_GENL_CMD_MAX, +}; +#define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1) + +#define ACPI_GENL_NAME "acpi_event" +#define ACPI_GENL_VERSION 0x01 + +static struct genl_family acpi_event_genl_family = { + .id = GENL_ID_GENERATE, + .name = ACPI_GENL_NAME, + .version = ACPI_GENL_VERSION, + .maxattr = ACPI_GENL_ATTR_MAX, +}; + +/* .doit: standard command callback */ +static int acpi_genl_cmd_event(struct sk_buff *skb, struct genl_info *info) +{ + struct acpi_genl_event *event = info->userhdr; + + if (!event) + ACPI_DEBUG_PRINT((ACPI_DB_WARN, "ACPI event: NULL\n")); + + return 0; +} + +static struct genl_ops acpi_event_genl_ops = { + .cmd = ACPI_GENL_CMD_EVENT, + .doit = acpi_genl_cmd_event, +}; + +int acpi_bus_generate_genetlink_event(struct acpi_device *device, + u8 type, int data) +{ + struct sk_buff *skb; + struct nlattr *attr; + struct acpi_genl_event *event; + void *msg_header; + int size; + int result; + + /* allocate memory */ + size = nla_total_size(sizeof(struct acpi_genl_event)) + + nla_total_size(0); + + skb = genlmsg_new(size, GFP_ATOMIC); + if (!skb) + return -ENOMEM; + + /* add the genetlink message header */ + msg_header = genlmsg_put(skb, 0, acpi_event_seqnum++, + &acpi_event_genl_family, 0, + ACPI_GENL_CMD_EVENT); + if (!msg_header) { + nlmsg_free(skb); + return -ENOMEM; + } + + /* fill the data */ + attr = + nla_reserve(skb, ACPI_GENL_ATTR_EVENT, + sizeof(struct acpi_genl_event)); + if (!attr) { + nlmsg_free(skb); + return -EINVAL; + } + + event = nla_data(attr); + if (!event) { + nlmsg_free(skb); + return -EINVAL; + } + + memset(event, 0, sizeof(struct acpi_genl_event)); + + strcpy(event->device_class, device->pnp.device_class); + strcpy(event->bus_id, device->dev.bus_id); + event->type = type; + event->data = data; + + /* send multicast genetlink message */ + result = genlmsg_end(skb, msg_header); + if (result < 0) { + nlmsg_free(skb); + return result; + } + + result = + genlmsg_multicast(skb, 0, acpi_event_genl_family.id, GFP_ATOMIC); + if (result) + ACPI_DEBUG_PRINT((ACPI_DB_INFO, + "Failed to send a Genetlink message!\n")); + return 0; +} +EXPORT_SYMBOL(acpi_bus_generate_genetlink_event); + +static int acpi_event_genetlink_init(void) +{ + int result; + + result = genl_register_family(&acpi_event_genl_family); + if (result) + return result; + + result = + genl_register_ops(&acpi_event_genl_family, &acpi_event_genl_ops); + if (result) + genl_unregister_family(&acpi_event_genl_family); + + return result; +} + +#else +int acpi_bus_generate_genetlink_event(struct acpi_device *device, u8 type, + int data) +{ + return 0; +} +EXPORT_SYMBOL(acpi_bus_generate_genetlink_event); + +static int acpi_event_genetlink_init(void) +{ + return -ENODEV; +} +#endif + static int __init acpi_event_init(void) { struct proc_dir_entry *entry; int error = 0; - if (acpi_disabled) return 0; + /* create genetlink for acpi event */ + error = acpi_event_genetlink_init(); + if (error) + printk(KERN_WARNING PREFIX + "Failed to create genetlink family for ACPI event\n"); + /* 'event' [R] */ entry = create_proc_entry("event", S_IRUSR, acpi_root_dir); if (entry) entry->proc_fops = &acpi_system_event_ops; - else { - error = -ENODEV; - } - return error; + else + return -ENODEV; + + return 0; } -subsys_initcall(acpi_event_init); +fs_initcall(acpi_event_init); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index c6fa5e023b..5e3dcf3299 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -321,7 +321,8 @@ struct acpi_bus_event { }; extern struct kset acpi_subsys; - +extern int acpi_bus_generate_genetlink_event(struct acpi_device *device, + u8 type, int data); /* * External Functions */ -- cgit v1.2.2 From b563d6f30d937510e02541930b1558d0f5759413 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Tue, 3 Jul 2007 15:32:23 -0400 Subject: ACPI: netlink: remove unnecessary EXPORT_SYMBOL Signed-off-by: Len Brown --- drivers/acpi/event.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c index 98627b02f5..de4def9b55 100644 --- a/drivers/acpi/event.c +++ b/drivers/acpi/event.c @@ -221,7 +221,6 @@ int acpi_bus_generate_genetlink_event(struct acpi_device *device, "Failed to send a Genetlink message!\n")); return 0; } -EXPORT_SYMBOL(acpi_bus_generate_genetlink_event); static int acpi_event_genetlink_init(void) { @@ -245,7 +244,6 @@ int acpi_bus_generate_genetlink_event(struct acpi_device *device, u8 type, { return 0; } -EXPORT_SYMBOL(acpi_bus_generate_genetlink_event); static int acpi_event_genetlink_init(void) { -- cgit v1.2.2 From 9254bc845db90a123cf992e983539d0ee409f22a Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Wed, 18 Jul 2007 01:10:24 -0400 Subject: ACPI: dock: fix oops when _DCK evaluation fails Data returned by acpi_get_name in acpi_buffer is not acpi_object and therefore should not be cast to it, otherwise we'll get an nice oops trying to print error message. Also print name of the ACPI object corresponding to the docking station and elevate severity of the message printed when _DCK fails to KERN_ERR. Signed-off-by: Dmitry Torokhov Cc: Kristen Carlson Accardi Signed-off-by: Len Brown --- drivers/acpi/dock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c index dc3df93d23..6192c8be66 100644 --- a/drivers/acpi/dock.c +++ b/drivers/acpi/dock.c @@ -396,12 +396,11 @@ static void handle_dock(struct dock_station *ds, int dock) union acpi_object arg; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL }; - union acpi_object *obj; acpi_get_name(ds->handle, ACPI_FULL_PATHNAME, &name_buffer); - obj = name_buffer.pointer; - printk(KERN_INFO PREFIX "%s\n", dock ? "docking" : "undocking"); + printk(KERN_INFO PREFIX "%s - %s\n", + (char *)name_buffer.pointer, dock ? "docking" : "undocking"); /* _DCK method has one argument */ arg_list.count = 1; @@ -410,7 +409,8 @@ static void handle_dock(struct dock_station *ds, int dock) arg.integer.value = dock; status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer); if (ACPI_FAILURE(status)) - pr_debug("%s: failed to execute _DCK\n", obj->string.pointer); + printk(KERN_ERR PREFIX "%s - failed to execute _DCK\n", + (char *)name_buffer.pointer); kfree(buffer.pointer); kfree(name_buffer.pointer); } -- cgit v1.2.2 From e6917317c0f6a930442c40dc38a6f21710adf961 Mon Sep 17 00:00:00 2001 From: Jesper Juhl Date: Thu, 19 Jul 2007 00:48:03 +0200 Subject: ACPICA: fix memory leak in acpi_ev_pci_config_region_setup() error path acpi_ev_pci_config_region_setup() leaks pci_id in the error case of "if (!pci_device_node)" Signed-off-by: Jesper Juhl Signed-off-by: Len Brown --- drivers/acpi/events/evrgnini.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c index 400d90fca9..23ee7bc4a7 100644 --- a/drivers/acpi/events/evrgnini.c +++ b/drivers/acpi/events/evrgnini.c @@ -284,6 +284,7 @@ acpi_ev_pci_config_region_setup(acpi_handle handle, } if (!pci_device_node) { + ACPI_FREE(pci_id); return_ACPI_STATUS(AE_AML_OPERAND_TYPE); } -- cgit v1.2.2 From 18eab8550397f1f3d4b8b2c5257c88dae25d58ed Mon Sep 17 00:00:00 2001 From: Venkatesh Pallipadi Date: Fri, 15 Jun 2007 19:37:00 -0400 Subject: ACPI: Enable C3 even when PM2_control is zero On systems that do not have pm2_control_block, we cannot really use ARB_DISABLE before C3. We used to disable C3 totally on such systems. To be compatible with Windows, we need to enable C3 on such systems now. We just skip ARB_DISABLE step before entering the C3-state and assume hardware is handling things correctly. Also, ACPI spec is not clear about pm2_control is _needed_ for C3 or not. We have atleast one system that need this to enable C3. Signed-off-by: Venkatesh Pallipadi Signed-off-by: Len Brown --- drivers/acpi/processor_idle.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c index ee5759bef9..36dc1d2652 100644 --- a/drivers/acpi/processor_idle.c +++ b/drivers/acpi/processor_idle.c @@ -488,7 +488,17 @@ static void acpi_processor_idle(void) case ACPI_STATE_C3: - if (pr->flags.bm_check) { + /* + * disable bus master + * bm_check implies we need ARB_DIS + * !bm_check implies we need cache flush + * bm_control implies whether we can do ARB_DIS + * + * That leaves a case where bm_check is set and bm_control is + * not set. In that case we cannot do much, we enter C3 + * without doing anything. + */ + if (pr->flags.bm_check && pr->flags.bm_control) { if (atomic_inc_return(&c3_cpu_count) == num_online_cpus()) { /* @@ -497,7 +507,7 @@ static void acpi_processor_idle(void) */ acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1); } - } else { + } else if (!pr->flags.bm_check) { /* SMP with no shared cache... Invalidate cache */ ACPI_FLUSH_CPU_CACHE(); } @@ -509,7 +519,7 @@ static void acpi_processor_idle(void) acpi_cstate_enter(cx); /* Get end time (ticks) */ t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); - if (pr->flags.bm_check) { + if (pr->flags.bm_check && pr->flags.bm_control) { /* Enable bus master arbitration */ atomic_dec(&c3_cpu_count); acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); @@ -959,9 +969,9 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr, if (pr->flags.bm_check) { /* bus mastering control is necessary */ if (!pr->flags.bm_control) { + /* In this case we enter C3 without bus mastering */ ACPI_DEBUG_PRINT((ACPI_DB_INFO, - "C3 support requires bus mastering control\n")); - return; + "C3 support without bus mastering control\n")); } } else { /* -- cgit v1.2.2 From b964b437601a0e7d09896d5d9a85c83643e94f41 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:26 -0300 Subject: ACPI: thinkpad-acpi: add DMI-based modalias Add DMI-based aliases to allow module autoloading on select thinkpads. The aliases will do nothing unless the dmi-based-module-autoloading.patch patch from Lennart Poettering is applied. Lennart's patch has been accepted by greghk and will be merged eventually. Signed-off-by: Henrique de Moraes Holschuh Cc: Lennart Poettering Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 95c0b96e83..22a5f228b5 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -92,6 +92,29 @@ MODULE_LICENSE("GPL"); /* Please remove this in year 2009 */ MODULE_ALIAS("ibm_acpi"); +/* + * DMI matching for module autoloading + * + * See http://thinkwiki.org/wiki/List_of_DMI_IDs + * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads + * + * Only models listed in thinkwiki will be supported, so add yours + * if it is not there yet. + */ +#define IBM_BIOS_MODULE_ALIAS(__type) \ + MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") + +/* Non-ancient thinkpads */ +MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); +MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); + +/* Ancient thinkpad BIOSes have to be identified by + * BIOS type or model number, and there are far less + * BIOS types than model numbers... */ +IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); +IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); +IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); + #define __unused __attribute__ ((unused)) /**************************************************************************** -- cgit v1.2.2 From 94954cc60194796fb257802f6f65d79553c9a8ca Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:27 -0300 Subject: ACPI: thinkpad-acpi: remove all uneeded initializers Remove all initializers to NULL or zero. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 22a5f228b5..9f10b4694e 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -129,7 +129,7 @@ IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); * ACPI basic handles */ -static acpi_handle root_handle = NULL; +static acpi_handle root_handle; #define IBM_HANDLE(object, parent, paths...) \ static acpi_handle object##_handle; \ @@ -515,8 +515,8 @@ static char *next_cmd(char **cmds) **************************************************************************** ****************************************************************************/ -static struct platform_device *tpacpi_pdev = NULL; -static struct class_device *tpacpi_hwmon = NULL; +static struct platform_device *tpacpi_pdev; +static struct class_device *tpacpi_hwmon; static struct platform_driver tpacpi_pdriver = { .driver = { @@ -729,7 +729,7 @@ static struct ibm_struct thinkpad_acpi_driver_data = { static int hotkey_orig_status; static int hotkey_orig_mask; -static struct attribute_set *hotkey_dev_attributes = NULL; +static struct attribute_set *hotkey_dev_attributes; /* sysfs hotkey enable ------------------------------------------------- */ static ssize_t hotkey_enable_show(struct device *dev, @@ -2694,7 +2694,7 @@ static struct ibm_struct ecdump_driver_data = { * Backlight/brightness subdriver */ -static struct backlight_device *ibm_backlight_device = NULL; +static struct backlight_device *ibm_backlight_device; static struct backlight_ops ibm_backlight_data = { .get_brightness = brightness_get, @@ -3497,7 +3497,7 @@ static void fan_watchdog_fire(struct work_struct *ignored) static void fan_watchdog_reset(void) { - static int fan_watchdog_active = 0; + static int fan_watchdog_active; if (fan_control_access_mode == TPACPI_FAN_WR_NONE) return; @@ -3900,7 +3900,7 @@ static struct ibm_struct fan_driver_data = { ****************************************************************************/ /* /proc support */ -static struct proc_dir_entry *proc_dir = NULL; +static struct proc_dir_entry *proc_dir; /* Subdriver registry */ static LIST_HEAD(tpacpi_all_drivers); @@ -4043,7 +4043,7 @@ static void ibm_exit(struct ibm_struct *ibm) /* Probing */ -static char *ibm_thinkpad_ec_found = NULL; +static char *ibm_thinkpad_ec_found; static char* __init check_dmi_for_ec(void) { -- cgit v1.2.2 From b8b26402cb711de5d3bbd4515b91b6d863fea259 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:28 -0300 Subject: ACPI: thinkpad-acpi: update information on T43 thermal sensor 0xc1 Update the documentation with some extra data on the T43 thermal sensor @0xc1, thanks to Alexey Fisher. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 9e6b94face..b90d9a7e81 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -562,7 +562,8 @@ http://thinkwiki.org/wiki/Thermal_Sensors#ThinkPad_T43.2C_T43p 2: System board, left side (near PCMCIA slot), reported as HDAPS temp 3: PCMCIA slot 9: MCH (northbridge) to DRAM Bus -10: ICH (southbridge), under Mini-PCI card, under touchpad +10: Clock-generator, mini-pci card and ICH (southbridge), under Mini-PCI + card, under touchpad 11: Power regulator, underside of system board, below F2 key The A31 has a very atypical layout for the thermal sensors -- cgit v1.2.2 From ae92bd17ff703b3703562148c73b4d6833e6a326 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:29 -0300 Subject: ACPI: thinkpad-acpi: enable more hotkeys Revise ACPI HKEY functionality to better interface with the firmware, and enable up to 32 regular hotkeys, instead of just 16 of them. Ouch. This takes care of most keys one used to have to do CMOS NVRAM polling on, and should drop the need for tpb, thinkpad-keys, and other such 5Hz NVRAM polling power vampires on most modern ThinkPads ;-) And, just to add insult to injury, this was sort of working since forever through the procfs interface, but nobody noticed or tried an echo 0xffffffff > /proc/acpi/ibm/hotkey and told me it would generate weird events. ARGH! Thanks to Richard Hughes for kicking off the work that ended up with this discovery, and to Matthew Garret for calling my attention to the fact that newer ThinkPads were indeed generating ACPI GPEs when such hot keys were pressed. Signed-off-by: Henrique de Moraes Holschuh Cc: Richard Hughes Cc: Matthew Garrett Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 41 +++++++++++++++++------------------------ drivers/misc/thinkpad_acpi.c | 38 ++++++++++++++++++++++---------------- drivers/misc/thinkpad_acpi.h | 6 +++--- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index b90d9a7e81..2f30db0e0d 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -153,29 +153,22 @@ addition, the lid microswitch and some docking station buttons may also generate such events. The bit mask allows some control over which hot keys generate ACPI -events. Not all bits in the mask can be modified. Not all bits that -can be modified do anything. Not all hot keys can be individually -controlled by the mask. Most recent ThinkPad models honor the -following bits (assuming the hot keys feature has been enabled): - - key bit behavior when set behavior when unset - - Fn-F3 always generates ACPI event - Fn-F4 always generates ACPI event - Fn-F5 0010 generate ACPI event enable/disable Bluetooth - Fn-F7 0040 generate ACPI event switch LCD and external display - Fn-F8 0080 generate ACPI event expand screen or none - Fn-F9 0100 generate ACPI event none - Fn-F12 always generates ACPI event - -Some models do not support all of the above. For example, the T30 does -not support Fn-F5 and Fn-F9. Other models do not support the mask at -all. On those models, hot keys cannot be controlled individually. +events. Not all bits in the mask can be modified. Not all bits that can +be modified do anything. Not all hot keys can be individually controlled +by the mask. Some models do not support the mask at all. On those +models, hot keys cannot be controlled individually. Note that enabling ACPI events for some keys prevents their default -behavior. For example, if events for Fn-F5 are enabled, that key will -no longer enable/disable Bluetooth by itself. This can still be done -from an acpid handler for the ibm/hotkey event. +behavior. For example, if events for Fn-F5 are enabled, that key will no +longer enable/disable Bluetooth by itself. This can still be done from +an acpid handler for the ibm/hotkey event. + +On some models, even enabling/disabling the entire hot key feature may +change the way some keys behave (e.g. in a T43, Fn+F4 will generate an +button/sleep ACPI event if hot keys are disabled, and it will ignore its +mask when hot keys are enabled, so the key always does something. On a +X40, Fn+F4 respects its mask status, but generates the button/sleep ACPI +event if masked off). Note also that not all Fn key combinations are supported through ACPI. For example, on the X40, the brightness, volume and "Access IBM" @@ -189,9 +182,9 @@ The following commands can be written to the /proc/acpi/ibm/hotkey file: echo enable > /proc/acpi/ibm/hotkey -- enable the hot keys feature echo disable > /proc/acpi/ibm/hotkey -- disable the hot keys feature - echo 0xffff > /proc/acpi/ibm/hotkey -- enable all possible hot keys - echo 0x0000 > /proc/acpi/ibm/hotkey -- disable all possible hot keys - ... any other 4-hex-digit mask ... + echo 0xffffffff > /proc/acpi/ibm/hotkey -- enable all hot keys + echo 0 > /proc/acpi/ibm/hotkey -- disable all possible hot keys + ... any other 8-hex-digit mask ... echo reset > /proc/acpi/ibm/hotkey -- restore the original mask sysfs notes: diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 9f10b4694e..450b1e5cd6 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -727,7 +727,7 @@ static struct ibm_struct thinkpad_acpi_driver_data = { */ static int hotkey_orig_status; -static int hotkey_orig_mask; +static u32 hotkey_orig_mask; static struct attribute_set *hotkey_dev_attributes; @@ -736,7 +736,8 @@ static ssize_t hotkey_enable_show(struct device *dev, struct device_attribute *attr, char *buf) { - int res, status, mask; + int res, status; + u32 mask; res = hotkey_get(&status, &mask); if (res) @@ -750,7 +751,8 @@ static ssize_t hotkey_enable_store(struct device *dev, const char *buf, size_t count) { unsigned long t; - int res, status, mask; + int res, status; + u32 mask; if (parse_strtoul(buf, 1, &t)) return -EINVAL; @@ -771,13 +773,14 @@ static ssize_t hotkey_mask_show(struct device *dev, struct device_attribute *attr, char *buf) { - int res, status, mask; + int res, status; + u32 mask; res = hotkey_get(&status, &mask); if (res) return res; - return snprintf(buf, PAGE_SIZE, "0x%04x\n", mask); + return snprintf(buf, PAGE_SIZE, "0x%08x\n", mask); } static ssize_t hotkey_mask_store(struct device *dev, @@ -785,9 +788,10 @@ static ssize_t hotkey_mask_store(struct device *dev, const char *buf, size_t count) { unsigned long t; - int res, status, mask; + int res, status; + u32 mask; - if (parse_strtoul(buf, 0xffff, &t)) + if (parse_strtoul(buf, 0xffffffffUL, &t)) return -EINVAL; res = hotkey_get(&status, &mask); @@ -817,7 +821,7 @@ static ssize_t hotkey_bios_mask_show(struct device *dev, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "0x%04x\n", hotkey_orig_mask); + return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask); } static struct device_attribute dev_attr_hotkey_bios_mask = @@ -902,10 +906,10 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event) { int hkey; - if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) + if (event == 0x80 && acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { acpi_bus_generate_event(ibm->acpi->device, event, hkey); - else { - printk(IBM_ERR "unknown hotkey event %d\n", event); + } else { + printk(IBM_ERR "unknown hotkey notification event %d\n", event); acpi_bus_generate_event(ibm->acpi->device, event, 0); } } @@ -913,7 +917,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event) /* * Call with hotkey_mutex held */ -static int hotkey_get(int *status, int *mask) +static int hotkey_get(int *status, u32 *mask) { if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) return -EIO; @@ -928,7 +932,7 @@ static int hotkey_get(int *status, int *mask) /* * Call with hotkey_mutex held */ -static int hotkey_set(int status, int mask) +static int hotkey_set(int status, u32 mask) { int i; @@ -949,7 +953,8 @@ static int hotkey_set(int status, int mask) /* procfs -------------------------------------------------------------- */ static int hotkey_read(char *p) { - int res, status, mask; + int res, status; + u32 mask; int len = 0; if (!tp_features.hotkey) { @@ -967,7 +972,7 @@ static int hotkey_read(char *p) len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); if (tp_features.hotkey_mask) { - len += sprintf(p + len, "mask:\t\t0x%04x\n", mask); + len += sprintf(p + len, "mask:\t\t0x%08x\n", mask); len += sprintf(p + len, "commands:\tenable, disable, reset, \n"); } else { @@ -980,7 +985,8 @@ static int hotkey_read(char *p) static int hotkey_write(char *buf) { - int res, status, mask; + int res, status; + u32 mask; char *cmd; int do_cmd = 0; diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index 72d62f2dab..e1a64f0aad 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -415,14 +415,14 @@ static int fan_write_cmd_watchdog(const char *cmd, int *rc); */ static int hotkey_orig_status; -static int hotkey_orig_mask; +static u32 hotkey_orig_mask; static struct mutex hotkey_mutex; static int hotkey_init(struct ibm_init_struct *iibm); static void hotkey_exit(void); -static int hotkey_get(int *status, int *mask); -static int hotkey_set(int status, int mask); +static int hotkey_get(int *status, u32 *mask); +static int hotkey_set(int status, u32 mask); static void hotkey_notify(struct ibm_struct *ibm, u32 event); static int hotkey_read(char *p); static int hotkey_write(char *buf); -- cgit v1.2.2 From 9b010de59cb6dcab7e167dd2a0fa5d3b31447fea Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:30 -0300 Subject: ACPI: thinkpad-acpi: export hotkey maximum masks The firmware knows how many hot keys it supports, so export this information in a sysfs attribute. And the driver knows which keys are always handled by the firmware in all known ThinkPad models too, so export this information as well in a sysfs attribute. Unless you know which events need to be handled in a passive way, do *not* enable hotkeys that are always handled by the firmware. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 13 +++++++++++++ drivers/misc/thinkpad_acpi.c | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 2f30db0e0d..142a14fa1d 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -214,6 +214,19 @@ sysfs notes: key (see above). Returns the current status of the hot keys mask, and allows one to modify it. + hotkey_all_mask: + bit mask that should enable event reporting for all + supported hot keys, when echoed to hotkey_mask above. + Unless you know which events need to be handled + passively (because the firmware *will* handle them + anyway), do *not* use hotkey_all_mask. Use + hotkey_recommended_mask, instead. You have been warned. + + hotkey_recommended_mask: + bit mask that should enable event reporting for all + supported hot keys, except those which are handled by + the firmware. Echo it to hotkey_mask above, to use. + Bluetooth --------- diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 450b1e5cd6..8c088687e9 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -728,6 +728,8 @@ static struct ibm_struct thinkpad_acpi_driver_data = { static int hotkey_orig_status; static u32 hotkey_orig_mask; +static u32 hotkey_all_mask; +static u32 hotkey_reserved_mask = 0x00778000; static struct attribute_set *hotkey_dev_attributes; @@ -827,12 +829,38 @@ static ssize_t hotkey_bios_mask_show(struct device *dev, static struct device_attribute dev_attr_hotkey_bios_mask = __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL); +/* sysfs hotkey all_mask ----------------------------------------------- */ +static ssize_t hotkey_all_mask_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_all_mask); +} + +static struct device_attribute dev_attr_hotkey_all_mask = + __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); + +/* sysfs hotkey recommended_mask --------------------------------------- */ +static ssize_t hotkey_recommended_mask_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return snprintf(buf, PAGE_SIZE, "0x%08x\n", + hotkey_all_mask & ~hotkey_reserved_mask); +} + +static struct device_attribute dev_attr_hotkey_recommended_mask = + __ATTR(hotkey_recommended_mask, S_IRUGO, + hotkey_recommended_mask_show, NULL); + /* --------------------------------------------------------------------- */ static struct attribute *hotkey_mask_attributes[] = { &dev_attr_hotkey_mask.attr, &dev_attr_hotkey_bios_enabled.attr, &dev_attr_hotkey_bios_mask.attr, + &dev_attr_hotkey_all_mask.attr, + &dev_attr_hotkey_recommended_mask.attr, }; static int __init hotkey_init(struct ibm_init_struct *iibm) @@ -851,7 +879,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) str_supported(tp_features.hotkey)); if (tp_features.hotkey) { - hotkey_dev_attributes = create_attr_set(4, NULL); + hotkey_dev_attributes = create_attr_set(6, NULL); if (!hotkey_dev_attributes) return -ENOMEM; res = add_to_attr_set(hotkey_dev_attributes, @@ -867,6 +895,13 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", str_supported(tp_features.hotkey_mask)); + if (tp_features.hotkey_mask) { + /* MHKA available in A31, R40, R40e, T4x, X31, and later */ + if (!acpi_evalf(hkey_handle, &hotkey_all_mask, + "MHKA", "qd")) + hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ + } + res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask); if (!res && tp_features.hotkey_mask) { res = add_many_to_attr_set(hotkey_dev_attributes, -- cgit v1.2.2 From 74941a69afcc06722685d492784414ec042ab492 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:31 -0300 Subject: ACPI: thinkpad-acpi: export to sysfs the state of the radio slider switch Some ThinkPad models, notably the T60 and X60, have a slider switch to enable and disable the radios. The switch has the capability of force-disabling the radios in hardware on most models, and it is supposed to affect all radios (WLAN, WWAN, BlueTooth). Export the switch state as a sysfs attribute, on ThinkPads where it is available. Thanks to Henning Schild for asking for this feature, and for tracking down the EC register that holds the radio switch state. Signed-off-by: Henrique de Moraes Holschuh Cc: Henning Schild Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 6 ++++++ drivers/misc/thinkpad_acpi.c | 38 ++++++++++++++++++++++++++++++++++++-- drivers/misc/thinkpad_acpi.h | 1 + 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 142a14fa1d..fe26e50a2b 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -227,6 +227,12 @@ sysfs notes: supported hot keys, except those which are handled by the firmware. Echo it to hotkey_mask above, to use. + hotkey_radio_sw: + if the ThinkPad has a hardware radio switch, this + attribute will read 0 if the switch is in the "radios + disabled" postition, and 1 if the switch is in the + "radios enabled" position. + Bluetooth --------- diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 8c088687e9..3cf37bb55e 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -733,6 +733,13 @@ static u32 hotkey_reserved_mask = 0x00778000; static struct attribute_set *hotkey_dev_attributes; +static int hotkey_get_wlsw(int *status) +{ + if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) + return -EIO; + return 0; +} + /* sysfs hotkey enable ------------------------------------------------- */ static ssize_t hotkey_enable_show(struct device *dev, struct device_attribute *attr, @@ -853,6 +860,22 @@ static struct device_attribute dev_attr_hotkey_recommended_mask = __ATTR(hotkey_recommended_mask, S_IRUGO, hotkey_recommended_mask_show, NULL); +/* sysfs hotkey radio_sw ----------------------------------------------- */ +static ssize_t hotkey_radio_sw_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int res, s; + res = hotkey_get_wlsw(&s); + if (res < 0) + return res; + + return snprintf(buf, PAGE_SIZE, "%d\n", !!s); +} + +static struct device_attribute dev_attr_hotkey_radio_sw = + __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); + /* --------------------------------------------------------------------- */ static struct attribute *hotkey_mask_attributes[] = { @@ -866,6 +889,7 @@ static struct attribute *hotkey_mask_attributes[] = { static int __init hotkey_init(struct ibm_init_struct *iibm) { int res; + int status; vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); @@ -879,7 +903,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) str_supported(tp_features.hotkey)); if (tp_features.hotkey) { - hotkey_dev_attributes = create_attr_set(6, NULL); + hotkey_dev_attributes = create_attr_set(7, NULL); if (!hotkey_dev_attributes) return -ENOMEM; res = add_to_attr_set(hotkey_dev_attributes, @@ -908,11 +932,21 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) hotkey_mask_attributes, ARRAY_SIZE(hotkey_mask_attributes)); } + + /* Not all thinkpads have a hardware radio switch */ + if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { + tp_features.hotkey_wlsw = 1; + printk(IBM_INFO + "radio switch found; radios are %s\n", + enabled(status, 0)); + res = add_to_attr_set(hotkey_dev_attributes, + &dev_attr_hotkey_radio_sw.attr); + } + if (!res) res = register_attr_set_with_sysfs( hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); - if (res) return res; } diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index e1a64f0aad..78ea4c88d5 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -228,6 +228,7 @@ static struct { u16 bluetooth:1; u16 hotkey:1; u16 hotkey_mask:1; + u16 hotkey_wlsw:1; u16 light:1; u16 light_status:1; u16 wan:1; -- cgit v1.2.2 From 94b08713186cc47a5c367a866cc0a0a762721455 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:32 -0300 Subject: ACPI: thinkpad-acpi: checkpoint sysfs interface version due to hotkey The change in the size of the hotkey mask, the hability to report the keys that use the higher bits, and the addition of the hotkey_radio_sw attribute are important enough features to warrant increasing the minor field of the sysfs interface version. Also, document a bit better how and when the thinkpad-acpi sysfs interface version will be updated. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 17 +++++++++++++++++ drivers/misc/thinkpad_acpi.c | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index fe26e50a2b..7a06a27ee3 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -134,6 +134,21 @@ end of this document. Changes to the sysfs interface done by the kernel subsystems are not documented here, nor are they tracked by this attribute. +Changes to the thinkpad-acpi sysfs interface are only considered +non-experimental when they are submitted to Linux mainline, at which +point the changes in this interface are documented and interface_version +may be updated. If you are using any thinkpad-acpi features not yet +sent to mainline for merging, you do so on your own risk: these features +may disappear, or be implemented in a different and incompatible way by +the time they are merged in Linux mainline. + +Changes that are backwards-compatible by nature (e.g. the addition of +attributes that do not change the way the other attributes work) do not +always warrant an update of interface_version. Therefore, one must +expect that an attribute might not be there, and deal with it properly +(an attribute not being there *is* a valid way to make it clear that a +feature is not available in sysfs). + Hot keys -------- @@ -989,3 +1004,5 @@ Sysfs interface changelog: 0x000100: Initial sysfs support, as a single platform driver and device. +0x000200: Hot key support for 32 hot keys, and radio slider switch + support. diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 3cf37bb55e..4d7189330e 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -22,7 +22,7 @@ */ #define IBM_VERSION "0.14" -#define TPACPI_SYSFS_VERSION 0x000100 +#define TPACPI_SYSFS_VERSION 0x000200 /* * Changelog: -- cgit v1.2.2 From d54b7d7f8026300c612dd733d501fcbc22fd0370 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:33 -0300 Subject: ACPI: thinkpad-acpi: update CMOS commands documentation The CMOS set of commands is often just used to keep the CMOS NVRAM in sync with whatever the ACPI BIOS has been doing in modern ThinkPads. In older ThinkPads, it actually carried out real actions. Document this. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 7a06a27ee3..bd00d14538 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -464,27 +464,34 @@ CMOS control procfs: /proc/acpi/ibm/cmos sysfs device attribute: cmos_command -This feature is used internally by the ACPI firmware to control the -ThinkLight on most newer ThinkPad models. It may also control LCD -brightness, sounds volume and more, but only on some models. +This feature is mostly used internally by the ACPI firmware to keep the legacy +CMOS NVRAM bits in sync with the current machine state, and to record this +state so that the ThinkPad will retain such settings across reboots. + +Some of these commands actually perform actions in some ThinkPad models, but +this is expected to disappear more and more in newer models. As an example, in +a T43 and in a X40, commands 12 and 13 still control the ThinkLight state for +real, but commands 0 to 2 don't control the mixer anymore (they have been +phased out) and just update the NVRAM. The range of valid cmos command numbers is 0 to 21, but not all have an effect and the behavior varies from model to model. Here is the behavior on the X40 (tpb is the ThinkPad Buttons utility): - 0 - no effect but tpb reports "Volume down" - 1 - no effect but tpb reports "Volume up" - 2 - no effect but tpb reports "Mute on" - 3 - simulate pressing the "Access IBM" button - 4 - LCD brightness up - 5 - LCD brightness down - 11 - toggle screen expansion - 12 - ThinkLight on - 13 - ThinkLight off - 14 - no effect but tpb reports ThinkLight status change + 0 - Related to "Volume down" key press + 1 - Related to "Volume up" key press + 2 - Related to "Mute on" key press + 3 - Related to "Access IBM" key press + 4 - Related to "LCD brightness up" key pess + 5 - Related to "LCD brightness down" key press + 11 - Related to "toggle screen expansion" key press/function + 12 - Related to "ThinkLight on" + 13 - Related to "ThinkLight off" + 14 - Related to "ThinkLight" key press (toggle thinklight) The cmos command interface is prone to firmware split-brain problems, as -in newer ThinkPads it is just a compatibility layer. +in newer ThinkPads it is just a compatibility layer. Do not use it, it is +exported just as a debug tool. LED control -- /proc/acpi/ibm/led --------------------------------- -- cgit v1.2.2 From 7f5d1cd6287b7b29d210f85e2343207ac4310da2 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:34 -0300 Subject: ACPI: thinkpad-acpi: register input device Register an input device to send input events to userspace. This patch is based on a patch by Richard Hughes . Signed-off-by: Henrique de Moraes Holschuh Cc: Richard Hughes Cc: Dmitry Torokhov Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 32 +++++++++++++++++++++++++++++++- drivers/misc/thinkpad_acpi.h | 9 +++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 4d7189330e..4427c994bc 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -510,13 +510,14 @@ static char *next_cmd(char **cmds) /**************************************************************************** **************************************************************************** * - * Device model: hwmon and platform + * Device model: input, hwmon and platform * **************************************************************************** ****************************************************************************/ static struct platform_device *tpacpi_pdev; static struct class_device *tpacpi_hwmon; +static struct input_dev *tpacpi_inputdev; static struct platform_driver tpacpi_pdriver = { .driver = { @@ -4363,6 +4364,20 @@ static int __init thinkpad_acpi_module_init(void) thinkpad_acpi_module_exit(); return ret; } + tpacpi_inputdev = input_allocate_device(); + if (!tpacpi_inputdev) { + printk(IBM_ERR "unable to allocate input device\n"); + thinkpad_acpi_module_exit(); + return -ENOMEM; + } else { + /* Prepare input device, but don't register */ + tpacpi_inputdev->name = "ThinkPad Extra Buttons"; + tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0"; + tpacpi_inputdev->id.bustype = BUS_HOST; + tpacpi_inputdev->id.vendor = TPACPI_HKEY_INPUT_VENDOR; + tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; + tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; + } for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { ret = ibm_init(&ibms_init[i]); if (ret >= 0 && *ibms_init[i].param) @@ -4372,6 +4387,14 @@ static int __init thinkpad_acpi_module_init(void) return ret; } } + ret = input_register_device(tpacpi_inputdev); + if (ret < 0) { + printk(IBM_ERR "unable to register input device\n"); + thinkpad_acpi_module_exit(); + return ret; + } else { + tp_features.input_device_registered = 1; + } return 0; } @@ -4388,6 +4411,13 @@ static void thinkpad_acpi_module_exit(void) dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); + if (tpacpi_inputdev) { + if (tp_features.input_device_registered) + input_unregister_device(tpacpi_inputdev); + else + input_free_device(tpacpi_inputdev); + } + if (tpacpi_hwmon) hwmon_device_unregister(tpacpi_hwmon); diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index 78ea4c88d5..00f1bd73df 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,7 @@ #include #include +#include /**************************************************************************** * Main driver @@ -98,6 +100,11 @@ static const char *str_supported(int is_supported); #define vdbg_printk(a_dbg_level, format, arg...) #endif +/* Input IDs */ +#define TPACPI_HKEY_INPUT_VENDOR PCI_VENDOR_ID_IBM +#define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */ +#define TPACPI_HKEY_INPUT_VERSION 0x4101 + /* ACPI HIDs */ #define IBM_HKEY_HID "IBM0068" #define IBM_PCI_HID "PNP0A03" @@ -161,6 +168,7 @@ static int parse_strtoul(const char *buf, unsigned long max, static struct platform_device *tpacpi_pdev; static struct class_device *tpacpi_hwmon; static struct platform_driver tpacpi_pdriver; +static struct input_dev *tpacpi_inputdev; static int tpacpi_create_driver_attributes(struct device_driver *drv); static void tpacpi_remove_driver_attributes(struct device_driver *drv); @@ -233,6 +241,7 @@ static struct { u16 light_status:1; u16 wan:1; u16 fan_ctrl_status_undef:1; + u16 input_device_registered:1; } tp_features; static struct list_head tpacpi_all_drivers; -- cgit v1.2.2 From 6a38abbf2b68e37493f2d5e8702b895a6c23ba0f Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:35 -0300 Subject: ACPI: thinkpad-acpi: add input device support to hotkey subdriver Add input device support to the hotkey subdriver. Hot keys that have a valid keycode mapping are reported through the input layer if the input device is open. Otherwise, they will be reported as ACPI events, as they were before. Scan codes are reported (using EV_MSC MSC_SCAN events) along with EV_KEY KEY_UNKNOWN events. For backwards compatibility purposes, hot keys that used to be reported through ACPI events are not mapped to anything meaningful by default. Userspace is supposed to remap them if it wants to use the input device for hot key reporting. This patch is based on a patch by Richard Hughes . Signed-off-by: Henrique de Moraes Holschuh Cc: Richard Hughes Cc: Dmitry Torokhov Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 151 ++++++++++++++++++++++++++++++++++++++++ drivers/misc/thinkpad_acpi.c | 108 ++++++++++++++++++++++++++-- 2 files changed, 255 insertions(+), 4 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index bd00d14538..91d08921a4 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -167,6 +167,17 @@ All labeled Fn-Fx key combinations generate distinct events. In addition, the lid microswitch and some docking station buttons may also generate such events. +Hot keys also generate regular keyboard key press/release events through +the input layer in addition to the ibm/hotkey ACPI events. The input +layer support accepts the standard IOCTLs to remap the keycodes assigned +to each hotkey. + +When the input device is open, the driver will suppress any ACPI hot key +events that get translated into a meaningful input layer event, in order +to avoid sending duplicate events to userspace. Hot keys that are +mapped to KEY_RESERVED are not translated, and will always generate only +ACPI hot key event, and no input layer events. + The bit mask allows some control over which hot keys generate ACPI events. Not all bits in the mask can be modified. Not all bits that can be modified do anything. Not all hot keys can be individually controlled @@ -248,6 +259,146 @@ sysfs notes: disabled" postition, and 1 if the switch is in the "radios enabled" position. +input layer notes: + +A Hot key is mapped to a single input layer EV_KEY event, possibly +followed by an EV_MSC MSC_SCAN event that shall contain that key's scan +code. An EV_SYN event will always be generated to mark the end of the +event block. + +Do not use the EV_MSC MSC_SCAN events to process keys. They are to be +used as a helper to remap keys, only. They are particularly useful when +remapping KEY_UNKNOWN keys. + +The events are available in an input device, with the following id: + + Bus: BUS_HOST + vendor: 0x1014 (PCI_VENDOR_ID_IBM) + product: 0x5054 ("TP") + version: 0x4101 + +The version will have its LSB incremented if the keymap changes in a +backwards-compatible way. The MSB shall always be 0x41 for this input +device. If the MSB is not 0x41, do not use the device as described in +this section, as it is either something else (e.g. another input device +exported by a thinkpad driver, such as HDAPS) or its functionality has +been changed in a non-backwards compatible way. + +Adding other event types for other functionalities shall be considered a +backwards-compatible change for this input device. + +Thinkpad-acpi Hot Key event map (version 0x4101): + +ACPI Scan +event code Key Notes + +0x1001 0x00 FN+F1 - +0x1002 0x01 FN+F2 - + +0x1003 0x02 FN+F3 Many models always report this + hot key, even with hot keys + disabled or with Fn+F3 masked + off + +0x1004 0x03 FN+F4 Sleep button (ACPI sleep button + semanthics, i.e. sleep-to-RAM). + It is always generate some kind + of event, either the hot key + event or a ACPI sleep button + event. The firmware may + refuse to generate further FN+F4 + key presses until a S3 or S4 ACPI + sleep cycle is performed or some + time passes. + +0x1005 0x04 FN+F5 Radio. Enables/disables + the internal BlueTooth hardware + and W-WAN card if left in control + of the firmware. Does not affect + the WLAN card. + +0x1006 0x05 FN+F6 - + +0x1007 0x06 FN+F7 Video output cycle. + Do you feel lucky today? + +0x1008 0x07 FN+F8 - + .. .. .. +0x100B 0x0A FN+F11 - + +0x100C 0x0B FN+F12 Sleep to disk. You are always + supposed to handle it yourself, + either through the ACPI event, + or through a hotkey event. + The firmware may refuse to + generate further FN+F4 key + press events until a S3 or S4 + ACPI sleep cycle is performed, + or some time passes. + +0x100D 0x0C FN+BACKSPACE - +0x100E 0x0D FN+INSERT - +0x100F 0x0E FN+DELETE - + +0x1010 0x0F FN+HOME Brightness up. This key is + always handled by the firmware, + even when unmasked. Just leave + it alone. +0x1011 0x10 FN+END Brightness down. This key is + always handled by the firmware, + even when unmasked. Just leave + it alone. +0x1012 0x11 FN+PGUP Thinklight toggle. This key is + always handled by the firmware, + even when unmasked. + +0x1013 0x12 FN+PGDOWN - + +0x1014 0x13 FN+SPACE Zoom key + +0x1015 0x14 VOLUME UP Internal mixer volume up. This + key is always handled by the + firmware, even when unmasked. +0x1016 0x15 VOLUME DOWN Internal mixer volume up. This + key is always handled by the + firmware, even when unmasked. +0x1017 0x16 MUTE Mute internal mixer. This + key is always handled by the + firmware, even when unmasked. + +0x1018 0x17 THINKPAD Thinkpad/Access IBM/Lenovo key + +0x1019 0x18 unknown +.. .. .. +0x1020 0x1F unknown + +The ThinkPad firmware does not allow one to differentiate when most hot +keys are pressed or released (either that, or we don't know how to, yet). +For these keys, the driver generates a set of events for a key press and +immediately issues the same set of events for a key release. It is +unknown by the driver if the ThinkPad firmware triggered these events on +hot key press or release, but the firmware will do it for either one, not +both. + +If a key is mapped to KEY_RESERVED, it generates no input events at all, +and it may generate a legacy thinkpad-acpi ACPI hotkey event. + +If a key is mapped to KEY_UNKNOWN, it generates an input event that +includes an scan code, and it may also generate a legacy thinkpad-acpi +ACPI hotkey event. + +If a key is mapped to anything else, it will only generate legacy +thinkpad-acpi ACPI hotkey events if nobody has opened the input device. + +For userspace backwards-compatibility purposes, the keycode map is +initially filled with KEY_RESERVED and KEY_UNKNOWN mappings for scan codes +0x00 to 0x10 (and maybe others). + +Non hot-key ACPI HKEY event map: +0x5001 Lid closed +0x5002 Lid opened +0x7000 Radio Switch may have changed state + Bluetooth --------- diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 4427c994bc..5c1bea1a6c 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -730,7 +730,31 @@ static struct ibm_struct thinkpad_acpi_driver_data = { static int hotkey_orig_status; static u32 hotkey_orig_mask; static u32 hotkey_all_mask; -static u32 hotkey_reserved_mask = 0x00778000; +static u32 hotkey_reserved_mask; + +static u16 hotkey_keycode_map[] = { + /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ + KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ + KEY_UNKNOWN, /* 0x0D: FN+INSERT */ + KEY_UNKNOWN, /* 0x0E: FN+DELETE */ + KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ + /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ + KEY_RESERVED, /* 0x10: FN+END (brightness down) */ + KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ + KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ + KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ + KEY_RESERVED, /* 0x14: VOLUME UP */ + KEY_RESERVED, /* 0x15: VOLUME DOWN */ + KEY_RESERVED, /* 0x16: MUTE */ + KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ + /* (assignments unknown, please report if found) */ + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, +}; static struct attribute_set *hotkey_dev_attributes; @@ -889,11 +913,13 @@ static struct attribute *hotkey_mask_attributes[] = { static int __init hotkey_init(struct ibm_init_struct *iibm) { - int res; + int res, i; int status; vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); + BUG_ON(!tpacpi_inputdev); + IBM_ACPIHANDLE_INIT(hkey); mutex_init(&hotkey_mutex); @@ -950,6 +976,23 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) &tpacpi_pdev->dev.kobj); if (res) return res; + + set_bit(EV_KEY, tpacpi_inputdev->evbit); + set_bit(EV_MSC, tpacpi_inputdev->evbit); + set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); + tpacpi_inputdev->keycodesize = sizeof(hotkey_keycode_map[0]); + tpacpi_inputdev->keycodemax = ARRAY_SIZE(hotkey_keycode_map); + tpacpi_inputdev->keycode = &hotkey_keycode_map; + for (i = 0; i < ARRAY_SIZE(hotkey_keycode_map); i++) { + if (hotkey_keycode_map[i] != KEY_RESERVED) { + set_bit(hotkey_keycode_map[i], + tpacpi_inputdev->keybit); + } else { + if (i < sizeof(hotkey_reserved_mask)*8) + hotkey_reserved_mask |= 1 << i; + } + } + } return (tp_features.hotkey)? 0 : 1; @@ -972,12 +1015,69 @@ static void hotkey_exit(void) } } +static void tpacpi_input_send_key(unsigned int scancode, + unsigned int keycode) +{ + if (keycode != KEY_RESERVED) { + input_report_key(tpacpi_inputdev, keycode, 1); + if (keycode == KEY_UNKNOWN) + input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, + scancode); + input_sync(tpacpi_inputdev); + + input_report_key(tpacpi_inputdev, keycode, 0); + if (keycode == KEY_UNKNOWN) + input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, + scancode); + input_sync(tpacpi_inputdev); + } +} + static void hotkey_notify(struct ibm_struct *ibm, u32 event) { - int hkey; + u32 hkey; + unsigned int keycode, scancode; + int sendacpi = 1; if (event == 0x80 && acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { - acpi_bus_generate_event(ibm->acpi->device, event, hkey); + if (tpacpi_inputdev->users > 0) { + switch (hkey >> 12) { + case 1: + /* 0x1000-0x1FFF: key presses */ + scancode = hkey & 0xfff; + if (scancode > 0 && scancode < 0x21) { + scancode--; + keycode = hotkey_keycode_map[scancode]; + tpacpi_input_send_key(scancode, keycode); + sendacpi = (keycode == KEY_RESERVED + || keycode == KEY_UNKNOWN); + } else { + printk(IBM_ERR + "hotkey 0x%04x out of range for keyboard map\n", + hkey); + } + break; + case 5: + /* 0x5000-0x5FFF: LID */ + /* we don't handle it through this path, just + * eat up known LID events */ + if (hkey != 0x5001 && hkey != 0x5002) { + printk(IBM_ERR + "unknown LID-related hotkey event: 0x%04x\n", + hkey); + } + break; + default: + /* case 2: dock-related */ + /* 0x2305 - T43 waking up due to bay lever eject while aslept */ + /* case 3: ultra-bay related. maybe bay in dock? */ + /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */ + printk(IBM_NOTICE "unhandled hotkey event 0x%04x\n", hkey); + } + } + + if (sendacpi) + acpi_bus_generate_event(ibm->acpi->device, event, hkey); } else { printk(IBM_ERR "unknown hotkey notification event %d\n", event); acpi_bus_generate_event(ibm->acpi->device, event, 0); -- cgit v1.2.2 From 1a343760b516ca5466d201bec32b1794858b18a5 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:36 -0300 Subject: ACPI: thinkpad-acpi: make the input event mode the default Make the input layer the default way to deal with thinkpad-acpi hot keys, but add a kernel config option to retain the old way of doing things. This means we map a lot more keys to useful stuff by default, and also that we enable hot key handling by default on driver load (like Windows does). The documentation for proper use of this resource is also updated. Signed-off-by: Henrique de Moraes Holschuh Cc: Richard Hughes Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 89 +++++++++++++++++++---------------------- drivers/misc/Kconfig | 13 ++++++ drivers/misc/thinkpad_acpi.c | 19 +++++++-- 3 files changed, 70 insertions(+), 51 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 91d08921a4..5b59cf50b2 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -155,52 +155,47 @@ Hot keys procfs: /proc/acpi/ibm/hotkey sysfs device attribute: hotkey_* -Without this driver, only the Fn-F4 key (sleep button) generates an -ACPI event. With the driver loaded, the hotkey feature enabled and the -mask set (see below), the various hot keys generate ACPI events in the +In a ThinkPad, the ACPI HKEY handler is responsible for comunicating +some important events and also keyboard hot key presses to the operating +system. Enabling the hotkey functionality of thinkpad-acpi signals the +firmware that such a driver is present, and modifies how the ThinkPad +firmware will behave in many situations. + +When the hotkey feature is enabled and the hot key mask is set (see +below), the various hot keys either generate ACPI events in the following format: ibm/hotkey HKEY 00000080 0000xxxx -The last four digits vary depending on the key combination pressed. -All labeled Fn-Fx key combinations generate distinct events. In -addition, the lid microswitch and some docking station buttons may -also generate such events. - -Hot keys also generate regular keyboard key press/release events through -the input layer in addition to the ibm/hotkey ACPI events. The input -layer support accepts the standard IOCTLs to remap the keycodes assigned -to each hotkey. +or events over the input layer. The input layer support accepts the +standard IOCTLs to remap the keycodes assigned to each hotkey. When the input device is open, the driver will suppress any ACPI hot key events that get translated into a meaningful input layer event, in order to avoid sending duplicate events to userspace. Hot keys that are -mapped to KEY_RESERVED are not translated, and will always generate only -ACPI hot key event, and no input layer events. - -The bit mask allows some control over which hot keys generate ACPI -events. Not all bits in the mask can be modified. Not all bits that can -be modified do anything. Not all hot keys can be individually controlled -by the mask. Some models do not support the mask at all. On those -models, hot keys cannot be controlled individually. - -Note that enabling ACPI events for some keys prevents their default -behavior. For example, if events for Fn-F5 are enabled, that key will no -longer enable/disable Bluetooth by itself. This can still be done from -an acpid handler for the ibm/hotkey event. - -On some models, even enabling/disabling the entire hot key feature may -change the way some keys behave (e.g. in a T43, Fn+F4 will generate an -button/sleep ACPI event if hot keys are disabled, and it will ignore its -mask when hot keys are enabled, so the key always does something. On a -X40, Fn+F4 respects its mask status, but generates the button/sleep ACPI -event if masked off). - -Note also that not all Fn key combinations are supported through -ACPI. For example, on the X40, the brightness, volume and "Access IBM" -buttons do not generate ACPI events even with this driver. They *can* -be used through the "ThinkPad Buttons" utility, see -http://www.nongnu.org/tpb/ +mapped to KEY_RESERVED in the keymap are not translated, and will always +generate an ACPI ibm/hotkey HKEY event, and no input layer events. + +The hot key bit mask allows some control over which hot keys generate +events. If a key is "masked" (bit set to 0 in the mask), the firmware +will handle it. If it is "unmasked", it signals the firmware that +thinkpad-acpi would prefer to handle it, if the firmware would be so +kind to allow it (and it often doesn't!). + +Not all bits in the mask can be modified. Not all bits that can be +modified do anything. Not all hot keys can be individually controlled +by the mask. Some models do not support the mask at all, and in those +models, hot keys cannot be controlled individually. The behaviour of +the mask is, therefore, higly dependent on the ThinkPad model. + +Note that unmasking some keys prevents their default behavior. For +example, if Fn+F5 is unmasked, that key will no longer enable/disable +Bluetooth by itself. + +Note also that not all Fn key combinations are supported through ACPI. +For example, on the X40, the brightness, volume and "Access IBM" buttons +do not generate ACPI events even with this driver. They *can* be used +through the "ThinkPad Buttons" utility, see http://www.nongnu.org/tpb/ procfs notes: @@ -221,7 +216,7 @@ sysfs notes: key feature status will be restored to this value. 0: hot keys were disabled - 1: hot keys were enabled + 1: hot keys were enabled (unusual) hotkey_bios_mask: Returns the hot keys mask when thinkpad-acpi was loaded. @@ -236,9 +231,10 @@ sysfs notes: 1: enables the hot keys feature / feature enabled hotkey_mask: - bit mask to enable ACPI event generation for each hot - key (see above). Returns the current status of the hot - keys mask, and allows one to modify it. + bit mask to enable driver-handling and ACPI event + generation for each hot key (see above). Returns the + current status of the hot keys mask, and allows one to + modify it. hotkey_all_mask: bit mask that should enable event reporting for all @@ -250,8 +246,9 @@ sysfs notes: hotkey_recommended_mask: bit mask that should enable event reporting for all - supported hot keys, except those which are handled by - the firmware. Echo it to hotkey_mask above, to use. + supported hot keys, except those which are always + handled by the firmware anyway. Echo it to + hotkey_mask above, to use. hotkey_radio_sw: if the ThinkPad has a hardware radio switch, this @@ -390,10 +387,6 @@ ACPI hotkey event. If a key is mapped to anything else, it will only generate legacy thinkpad-acpi ACPI hotkey events if nobody has opened the input device. -For userspace backwards-compatibility purposes, the keycode map is -initially filled with KEY_RESERVED and KEY_UNKNOWN mappings for scan codes -0x00 to 0x10 (and maybe others). - Non hot-key ACPI HKEY event map: 0x5001 Lid closed 0x5002 Lid opened diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 1d516f24ba..5197f9b9b6 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -196,4 +196,17 @@ config THINKPAD_ACPI_BAY If you are not sure, say Y here. +config THINKPAD_ACPI_INPUT_ENABLED + bool "Enable input layer support by default" + depends on THINKPAD_ACPI + default y + ---help--- + Enables hot key handling over the input layer by default. If unset, + the driver does not enable any hot key handling by default, and also + starts up with a mostly empty keymap. + + If you are not sure, say Y here. Say N to retain the deprecated + behavior of ibm-acpi, and thinkpad-acpi for kernels up to 2.6.21. + + endif # MISC_DEVICES diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 5c1bea1a6c..c86b228375 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -734,9 +734,9 @@ static u32 hotkey_reserved_mask; static u16 hotkey_keycode_map[] = { /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + KEY_FN_F1, KEY_FN_F2, KEY_FN_F3, KEY_SLEEP, + KEY_FN_F5, KEY_FN_F6, KEY_FN_F7, KEY_FN_F8, + KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ KEY_UNKNOWN, /* 0x0D: FN+INSERT */ @@ -977,6 +977,11 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) if (res) return res; +#ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED + for (i = 0; i < 12; i++) + hotkey_keycode_map[i] = KEY_UNKNOWN; +#endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */ + set_bit(EV_KEY, tpacpi_inputdev->evbit); set_bit(EV_MSC, tpacpi_inputdev->evbit); set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); @@ -993,6 +998,14 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) } } +#ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED + dbg_printk(TPACPI_DBG_INIT, + "enabling hot key handling\n"); + res = hotkey_set(1, (hotkey_all_mask & ~hotkey_reserved_mask) + | hotkey_orig_mask); + if (res) + return res; +#endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */ } return (tp_features.hotkey)? 0 : 1; -- cgit v1.2.2 From e295e8508c1dd56e06c73e78a2f67f2eb563e74f Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:37 -0300 Subject: ACPI: thinkpad-acpi: add power-management handler capability Some subdrivers could benefit from resume handling, so add the infrastructure for simple resume handling. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 16 ++++++++++++++++ drivers/misc/thinkpad_acpi.h | 1 + 2 files changed, 17 insertions(+) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index c86b228375..78914bf216 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -519,11 +519,27 @@ static struct platform_device *tpacpi_pdev; static struct class_device *tpacpi_hwmon; static struct input_dev *tpacpi_inputdev; + +static int tpacpi_resume_handler(struct platform_device *pdev) +{ + struct ibm_struct *ibm, *itmp; + + list_for_each_entry_safe(ibm, itmp, + &tpacpi_all_drivers, + all_drivers) { + if (ibm->resume) + (ibm->resume)(); + } + + return 0; +} + static struct platform_driver tpacpi_pdriver = { .driver = { .name = IBM_DRVR_NAME, .owner = THIS_MODULE, }, + .resume = tpacpi_resume_handler, }; diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index 00f1bd73df..c5c1316ae3 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -205,6 +205,7 @@ struct ibm_struct { int (*read) (char *); int (*write) (char *); void (*exit) (void); + void (*resume) (void); struct list_head all_drivers; -- cgit v1.2.2 From 5c29d58f471099401513e2e567f6c28001bb0f13 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:38 -0300 Subject: ACPI: thinkpad-acpi: export EV_SW SW_RADIO events The expected user case for the radio slider switch on a ThinkPad includes interfacing to applications, so that the user gets an offer to find and associate with a wireless network when the switch is changed from disabled to enabled (ThinkVantage suite). Export the information about the switch state, and switch change events as an EV_SW SW_RADIO event over the input layer. Signed-off-by: Henrique de Moraes Holschuh Cc: Dmitry Torokhov Cc: Ivo van Doorn Cc: Richard Hughes Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 78914bf216..cfef218c45 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -1014,6 +1014,11 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) } } + if (tp_features.hotkey_wlsw) { + set_bit(EV_SW, tpacpi_inputdev->evbit); + set_bit(SW_RADIO, tpacpi_inputdev->swbit); + } + #ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED dbg_printk(TPACPI_DBG_INIT, "enabling hot key handling\n"); @@ -1062,6 +1067,15 @@ static void tpacpi_input_send_key(unsigned int scancode, } } +static void tpacpi_input_send_radiosw(void) +{ + int wlsw; + + if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) + input_report_switch(tpacpi_inputdev, + SW_RADIO, !!wlsw); +} + static void hotkey_notify(struct ibm_struct *ibm, u32 event) { u32 hkey; @@ -1096,6 +1110,14 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event) hkey); } break; + case 7: + /* 0x7000-0x7FFF: misc */ + if (tp_features.hotkey_wlsw && hkey == 0x7000) { + tpacpi_input_send_radiosw(); + sendacpi = 0; + break; + } + /* fallthrough to default */ default: /* case 2: dock-related */ /* 0x2305 - T43 waking up due to bay lever eject while aslept */ @@ -1113,6 +1135,11 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event) } } +static void hotkey_resume(void) +{ + tpacpi_input_send_radiosw(); +} + /* * Call with hotkey_mutex held */ @@ -1240,6 +1267,7 @@ static struct ibm_struct hotkey_driver_data = { .read = hotkey_read, .write = hotkey_write, .exit = hotkey_exit, + .resume = hotkey_resume, .acpi = &ibm_hotkey_acpidriver, }; -- cgit v1.2.2 From 741553c2d29b4075d636a38792c05cd2fc62bd8a Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:39 -0300 Subject: ACPI: thinkpad-acpi: checkpoint sysfs interface version due to input layer The change in the way hotkey events are handled by default, and the use of the input layer for the hotkey events are important enough features to warrant increasing the major field of the sysfs interface version. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 4 ++++ drivers/misc/thinkpad_acpi.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 5b59cf50b2..c670363cf5 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -1157,3 +1157,7 @@ Sysfs interface changelog: device. 0x000200: Hot key support for 32 hot keys, and radio slider switch support. +0x010000: Hot keys are now handled by default over the input + layer, the radio switch generates input event EV_RADIO, + and the driver enables hot key handling by default in + the firmware. diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index cfef218c45..c1e6a01d08 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -22,7 +22,7 @@ */ #define IBM_VERSION "0.14" -#define TPACPI_SYSFS_VERSION 0x000200 +#define TPACPI_SYSFS_VERSION 0x010000 /* * Changelog: -- cgit v1.2.2 From 996fba08db7faf46b1a674957f60cd772ecd29ec Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:40 -0300 Subject: ACPI: thinkpad-acpi: rename pci HID constant Rename an internal driver constant, on request by Len Brown. Also, document exactly what it is for. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 7 +++++-- drivers/misc/thinkpad_acpi.h | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index c1e6a01d08..78e41102a9 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -2026,7 +2026,10 @@ static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { .type = ACPI_SYSTEM_NOTIFY, }, { - .hid = IBM_PCI_HID, + /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. + * We just use it to get notifications of dock hotplug + * in very old thinkpads */ + .hid = PCI_ROOT_HID_STRING, .notify = dock_notify, .handle = &pci_handle, .type = ACPI_SYSTEM_NOTIFY, @@ -2085,7 +2088,7 @@ static int __init dock_init2(struct ibm_init_struct *iibm) static void dock_notify(struct ibm_struct *ibm, u32 event) { int docked = dock_docked(); - int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID); + int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, PCI_ROOT_HID_STRING); if (event == 1 && !pci) /* 570 */ acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */ diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index c5c1316ae3..fee04214a1 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -107,7 +107,6 @@ static const char *str_supported(int is_supported); /* ACPI HIDs */ #define IBM_HKEY_HID "IBM0068" -#define IBM_PCI_HID "PNP0A03" /* ACPI helpers */ static int __must_check acpi_evalf(acpi_handle handle, -- cgit v1.2.2 From 86cc9445e86bef9da44f933e3849e6eb43cbf626 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:41 -0300 Subject: ACPI: thinkpad_acpi: use bool for boolean parameters Some of the module parameters are boolean in nature. Make it so in fact. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 78e41102a9..44aa8c92f9 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -4444,10 +4444,10 @@ static u32 dbg_level; module_param_named(debug, dbg_level, uint, 0); static int force_load; -module_param(force_load, int, 0); +module_param(force_load, bool, 0); static int fan_control_allowed; -module_param_named(fan_control, fan_control_allowed, int, 0); +module_param_named(fan_control, fan_control_allowed, bool, 0); #define IBM_PARAM(feature) \ module_param_call(feature, set_ibm_param, NULL, NULL, 0) -- cgit v1.2.2 From d5a2f2f1d68e2da538ac28540cddd9ccc733b001 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:42 -0300 Subject: ACPI: thinkpad-acpi: store ThinkPad model information Keep note of ThinkPad model, BIOS and EC firmware information, and log it on startup. Makes for far more readable code in places, too. This patch also adds Lenovo's PCI ID to the pci ids table. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 98 +++++++++++++++++++++++++++++++------------- drivers/misc/thinkpad_acpi.h | 17 +++++++- include/linux/pci_ids.h | 2 + 3 files changed, 87 insertions(+), 30 deletions(-) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 44aa8c92f9..99500af651 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -717,9 +717,19 @@ static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); printk(IBM_INFO "%s\n", IBM_URL); - if (ibm_thinkpad_ec_found) - printk(IBM_INFO "ThinkPad EC firmware %s\n", - ibm_thinkpad_ec_found); + printk(IBM_INFO "ThinkPad BIOS %s, EC %s\n", + (thinkpad_id.bios_version_str) ? + thinkpad_id.bios_version_str : "unknown", + (thinkpad_id.ec_version_str) ? + thinkpad_id.ec_version_str : "unknown"); + + if (thinkpad_id.vendor && thinkpad_id.model_str) + printk(IBM_INFO "%s %s\n", + (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? + "IBM" : ((thinkpad_id.vendor == + PCI_VENDOR_ID_LENOVO) ? + "Lenovo" : "Unknown vendor"), + thinkpad_id.model_str); return 0; } @@ -2648,7 +2658,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm) acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); - if (ibm_thinkpad_ec_found && experimental) { + if (thinkpad_id.ec_model && experimental) { /* * Direct EC access mode: sensors at registers * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for @@ -3532,20 +3542,19 @@ static int __init fan_init(struct ibm_init_struct *iibm) * Enable for TP-1Y (T43), TP-78 (R51e), * TP-76 (R52), TP-70 (T43, R52), which are known * to be buggy. */ - if (fan_control_initial_status == 0x07 && - ibm_thinkpad_ec_found && - ((ibm_thinkpad_ec_found[0] == '1' && - ibm_thinkpad_ec_found[1] == 'Y') || - (ibm_thinkpad_ec_found[0] == '7' && - (ibm_thinkpad_ec_found[1] == '6' || - ibm_thinkpad_ec_found[1] == '8' || - ibm_thinkpad_ec_found[1] == '0')) - )) { - printk(IBM_NOTICE - "fan_init: initial fan status is " - "unknown, assuming it is in auto " - "mode\n"); - tp_features.fan_ctrl_status_undef = 1; + if (fan_control_initial_status == 0x07) { + switch (thinkpad_id.ec_model) { + case 0x5931: /* TP-1Y */ + case 0x3837: /* TP-78 */ + case 0x3637: /* TP-76 */ + case 0x3037: /* TP-70 */ + printk(IBM_NOTICE + "fan_init: initial fan status is " + "unknown, assuming it is in auto " + "mode\n"); + tp_features.fan_ctrl_status_undef = 1; + ;; + } } } else { printk(IBM_ERR @@ -4279,13 +4288,30 @@ static void ibm_exit(struct ibm_struct *ibm) /* Probing */ -static char *ibm_thinkpad_ec_found; - -static char* __init check_dmi_for_ec(void) +static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp) { struct dmi_device *dev = NULL; char ec_fw_string[18]; + if (!tp) + return; + + memset(tp, 0, sizeof(*tp)); + + if (dmi_name_in_vendors("IBM")) + tp->vendor = PCI_VENDOR_ID_IBM; + else if (dmi_name_in_vendors("LENOVO")) + tp->vendor = PCI_VENDOR_ID_LENOVO; + else + return; + + tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), + GFP_KERNEL); + if (!tp->bios_version_str) + return; + tp->bios_model = tp->bios_version_str[0] + | (tp->bios_version_str[1] << 8); + /* * ThinkPad T23 or newer, A31 or newer, R50e or newer, * X32 or newer, all Z series; Some models must have an @@ -4299,10 +4325,20 @@ static char* __init check_dmi_for_ec(void) ec_fw_string) == 1) { ec_fw_string[sizeof(ec_fw_string) - 1] = 0; ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; - return kstrdup(ec_fw_string, GFP_KERNEL); + + tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); + tp->ec_model = ec_fw_string[0] + | (ec_fw_string[1] << 8); + break; } } - return NULL; + + tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), + GFP_KERNEL); + if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) { + kfree(tp->model_str); + tp->model_str = NULL; + } } static int __init probe_for_thinkpad(void) @@ -4316,7 +4352,7 @@ static int __init probe_for_thinkpad(void) * Non-ancient models have better DMI tagging, but very old models * don't. */ - is_thinkpad = dmi_name_in_vendors("ThinkPad"); + is_thinkpad = (thinkpad_id.model_str != NULL); /* ec is required because many other handles are relative to it */ IBM_ACPIHANDLE_INIT(ec); @@ -4332,7 +4368,7 @@ static int __init probe_for_thinkpad(void) * false positives a damn great deal */ if (!is_thinkpad) - is_thinkpad = dmi_name_in_vendors("IBM"); + is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); if (!is_thinkpad && !force_load) return -ENODEV; @@ -4475,12 +4511,16 @@ static int __init thinkpad_acpi_module_init(void) int ret, i; /* Driver-level probe */ + + get_thinkpad_model_data(&thinkpad_id); ret = probe_for_thinkpad(); - if (ret) + if (ret) { + thinkpad_acpi_module_exit(); return ret; + } /* Driver initialization */ - ibm_thinkpad_ec_found = check_dmi_for_ec(); + IBM_ACPIHANDLE_INIT(ecrd); IBM_ACPIHANDLE_INIT(ecwr); @@ -4590,7 +4630,9 @@ static void thinkpad_acpi_module_exit(void) if (proc_dir) remove_proc_entry(IBM_PROC_DIR, acpi_root_dir); - kfree(ibm_thinkpad_ec_found); + kfree(thinkpad_id.bios_version_str); + kfree(thinkpad_id.ec_version_str); + kfree(thinkpad_id.model_str); } module_init(thinkpad_acpi_module_init); diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index fee04214a1..09b2282fed 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -175,9 +175,7 @@ static void tpacpi_remove_driver_attributes(struct device_driver *drv); static int experimental; static u32 dbg_level; static int force_load; -static char *ibm_thinkpad_ec_found; -static char* check_dmi_for_ec(void); static int thinkpad_acpi_module_init(void); static void thinkpad_acpi_module_exit(void); @@ -244,6 +242,21 @@ static struct { u16 input_device_registered:1; } tp_features; +struct thinkpad_id_data { + unsigned int vendor; /* ThinkPad vendor: + * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */ + + char *bios_version_str; /* Something like 1ZET51WW (1.03z) */ + char *ec_version_str; /* Something like 1ZHT51WW-1.04a */ + + u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */ + u16 ec_model; + + char *model_str; +}; + +static struct thinkpad_id_data thinkpad_id; + static struct list_head tpacpi_all_drivers; static struct ibm_init_struct ibms_init[]; diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index b15c6498fe..ced4d3f761 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h @@ -2040,6 +2040,8 @@ #define PCI_DEVICE_ID_ALTIMA_AC9100 0x03ea #define PCI_DEVICE_ID_ALTIMA_AC1003 0x03eb +#define PCI_VENDOR_ID_LENOVO 0x17aa + #define PCI_VENDOR_ID_ARECA 0x17d3 #define PCI_DEVICE_ID_ARECA_1110 0x1110 #define PCI_DEVICE_ID_ARECA_1120 0x1120 -- cgit v1.2.2 From 24d3b77467b6aaf59e38dce4aa86d05541858195 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:43 -0300 Subject: ACPI: thinkpad-acpi: allow use of CMOS NVRAM for brightness control It appears that Lenovo decided to break the EC brightness control interface in a weird way in their latest BIOSes. Fortunately, the old CMOS NVRAM interface works just fine in such BIOSes. Add a module parameter that allows the user to select which strategy to use for brightness control: EC, NVRAM, or both. By default, do both (which is the way thinkpad-acpi used to work until now) on IBM ThinkPads, and use NVRAM only on Lenovo ThinkPads. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 6 ++++ drivers/misc/Kconfig | 1 + drivers/misc/thinkpad_acpi.c | 62 +++++++++++++++++++++++++++++++++++------ drivers/misc/thinkpad_acpi.h | 7 +++++ 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index c670363cf5..c145bcce23 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -860,6 +860,12 @@ cannot be controlled. The backlight control has eight levels, ranging from 0 to 7. Some of the levels may not be distinct. +There are two interfaces to the firmware for brightness control, EC and CMOS. +To select which one should be used, use the brightness_mode module parameter: +brightness_mode=1 selects EC mode, brightness_mode=2 selects CMOS mode, +brightness_mode=3 selects both EC and CMOS. The driver tries to autodetect +which interface to use. + Procfs notes: The available commands are: diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 5197f9b9b6..aaaa61ea42 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -150,6 +150,7 @@ config THINKPAD_ACPI depends on X86 && ACPI select BACKLIGHT_CLASS_DEVICE select HWMON + select NVRAM ---help--- This is a driver for the IBM and Lenovo ThinkPad laptops. It adds support for Fn-Fx key combinations, Bluetooth control, video diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 99500af651..5318eb272c 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -2953,9 +2953,22 @@ static int __init brightness_init(struct ibm_init_struct *iibm) vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); + if (!brightness_mode) { + if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) + brightness_mode = 2; + else + brightness_mode = 3; + + dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n", + brightness_mode); + } + + if (brightness_mode > 3) + return -EINVAL; + b = brightness_get(NULL); if (b < 0) - return b; + return 1; ibm_backlight_device = backlight_device_register( TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, @@ -2991,13 +3004,35 @@ static int brightness_update_status(struct backlight_device *bd) bd->props.brightness : 0); } +/* + * ThinkPads can read brightness from two places: EC 0x31, or + * CMOS NVRAM byte 0x5E, bits 0-3. + */ static int brightness_get(struct backlight_device *bd) { - u8 level; - if (!acpi_ec_read(brightness_offset, &level)) - return -EIO; + u8 lec = 0, lcmos = 0, level = 0; - level &= 0x7; + if (brightness_mode & 1) { + if (!acpi_ec_read(brightness_offset, &lec)) + return -EIO; + lec &= 7; + level = lec; + }; + if (brightness_mode & 2) { + lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) + & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) + >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; + level = lcmos; + } + + if (brightness_mode == 3 && lec != lcmos) { + printk(IBM_ERR + "CMOS NVRAM (%u) and EC (%u) do not agree " + "on display brightness level\n", + (unsigned int) lcmos, + (unsigned int) lec); + return -EIO; + } return level; } @@ -3007,14 +3042,20 @@ static int brightness_set(int value) int cmos_cmd, inc, i; int current_value = brightness_get(NULL); - value &= 7; + if (value > 7) + return -EINVAL; - cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; + cmos_cmd = value > current_value ? + TP_CMOS_BRIGHTNESS_UP : + TP_CMOS_BRIGHTNESS_DOWN; inc = value > current_value ? 1 : -1; + for (i = current_value; i != value; i += inc) { - if (issue_thinkpad_cmos_command(cmos_cmd)) + if ((brightness_mode & 2) && + issue_thinkpad_cmos_command(cmos_cmd)) return -EIO; - if (!acpi_ec_write(brightness_offset, i + inc)) + if ((brightness_mode & 1) && + !acpi_ec_write(brightness_offset, i + inc)) return -EIO; } @@ -4485,6 +4526,9 @@ module_param(force_load, bool, 0); static int fan_control_allowed; module_param_named(fan_control, fan_control_allowed, bool, 0); +static int brightness_mode; +module_param_named(brightness_mode, brightness_mode, int, 0); + #define IBM_PARAM(feature) \ module_param_call(feature, set_ibm_param, NULL, NULL, 0) diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h index 09b2282fed..b7a4a888cc 100644 --- a/drivers/misc/thinkpad_acpi.h +++ b/drivers/misc/thinkpad_acpi.h @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -80,6 +81,11 @@ #define TP_CMOS_BRIGHTNESS_UP 4 #define TP_CMOS_BRIGHTNESS_DOWN 5 +/* ThinkPad CMOS NVRAM constants */ +#define TP_NVRAM_ADDR_BRIGHTNESS 0x5e +#define TP_NVRAM_MASK_LEVEL_BRIGHTNESS 0x07 +#define TP_NVRAM_POS_LEVEL_BRIGHTNESS 0 + #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") #define strlencmp(a,b) (strncmp((a), (b), strlen(b))) @@ -323,6 +329,7 @@ static int bluetooth_write(char *buf); static struct backlight_device *ibm_backlight_device; static int brightness_offset = 0x31; +static int brightness_mode; static int brightness_init(struct ibm_init_struct *iibm); static void brightness_exit(void); -- cgit v1.2.2 From edf0e0e56904f794c97ca6c4562d8256e3d8d8e3 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:44 -0300 Subject: ACPI: thinkpad-acpi: react to Lenovo ThinkPad differences in hot key Lenovo ThinkPads have a slightly different key map layout from IBM ThinkPads (fn+f2 and fn+f3 are swapped). Knowing which one we are dealing with, we can properly set a few more hot keys up by default. Also, export the correct vendor in the input device, as that information might be useful to userspace. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 40 ++++++++++----- drivers/misc/thinkpad_acpi.c | 109 +++++++++++++++++++++++++++++----------- 2 files changed, 109 insertions(+), 40 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index c145bcce23..5d827ded34 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -270,7 +270,8 @@ remapping KEY_UNKNOWN keys. The events are available in an input device, with the following id: Bus: BUS_HOST - vendor: 0x1014 (PCI_VENDOR_ID_IBM) + vendor: 0x1014 (PCI_VENDOR_ID_IBM) or + 0x17aa (PCI_VENDOR_ID_LENOVO) product: 0x5054 ("TP") version: 0x4101 @@ -290,12 +291,15 @@ ACPI Scan event code Key Notes 0x1001 0x00 FN+F1 - -0x1002 0x01 FN+F2 - +0x1002 0x01 FN+F2 IBM: battery (rare) + Lenovo: Screen lock -0x1003 0x02 FN+F3 Many models always report this - hot key, even with hot keys +0x1003 0x02 FN+F3 Many IBM models always report + this hot key, even with hot keys disabled or with Fn+F3 masked off + IBM: screen lock + Lenovo: battery 0x1004 0x03 FN+F4 Sleep button (ACPI sleep button semanthics, i.e. sleep-to-RAM). @@ -313,13 +317,19 @@ event code Key Notes and W-WAN card if left in control of the firmware. Does not affect the WLAN card. + Should be used to turn on/off all + radios (bluetooth+W-WAN+WLAN), + really. 0x1006 0x05 FN+F6 - 0x1007 0x06 FN+F7 Video output cycle. Do you feel lucky today? -0x1008 0x07 FN+F8 - +0x1008 0x07 FN+F8 IBM: toggle screen expand + Lenovo: configure ultranav + +0x1009 0x08 FN+F9 - .. .. .. 0x100B 0x0A FN+F11 - @@ -338,13 +348,15 @@ event code Key Notes 0x100F 0x0E FN+DELETE - 0x1010 0x0F FN+HOME Brightness up. This key is - always handled by the firmware, - even when unmasked. Just leave - it alone. -0x1011 0x10 FN+END Brightness down. This key is - always handled by the firmware, - even when unmasked. Just leave - it alone. + always handled by the firmware + in IBM ThinkPads, even when + unmasked. Just leave it alone. + For Lenovo ThinkPads with a new + BIOS, it has to be handled either + by the ACPI OSI, or by userspace. +0x1011 0x10 FN+END Brightness down. See brightness + up for details. + 0x1012 0x11 FN+PGUP Thinklight toggle. This key is always handled by the firmware, even when unmasked. @@ -356,9 +368,13 @@ event code Key Notes 0x1015 0x14 VOLUME UP Internal mixer volume up. This key is always handled by the firmware, even when unmasked. + NOTE: Lenovo seems to be changing + this. 0x1016 0x15 VOLUME DOWN Internal mixer volume up. This key is always handled by the firmware, even when unmasked. + NOTE: Lenovo seems to be changing + this. 0x1017 0x16 MUTE Mute internal mixer. This key is always handled by the firmware, even when unmasked. diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 5318eb272c..623d36fd8d 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -758,29 +758,7 @@ static u32 hotkey_orig_mask; static u32 hotkey_all_mask; static u32 hotkey_reserved_mask; -static u16 hotkey_keycode_map[] = { - /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ - KEY_FN_F1, KEY_FN_F2, KEY_FN_F3, KEY_SLEEP, - KEY_FN_F5, KEY_FN_F6, KEY_FN_F7, KEY_FN_F8, - KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, - /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ - KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ - KEY_UNKNOWN, /* 0x0D: FN+INSERT */ - KEY_UNKNOWN, /* 0x0E: FN+DELETE */ - KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ - /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ - KEY_RESERVED, /* 0x10: FN+END (brightness down) */ - KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ - KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ - KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ - KEY_RESERVED, /* 0x14: VOLUME UP */ - KEY_RESERVED, /* 0x15: VOLUME DOWN */ - KEY_RESERVED, /* 0x16: MUTE */ - KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ - /* (assignments unknown, please report if found) */ - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, - KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, -}; +static u16 *hotkey_keycode_map; static struct attribute_set *hotkey_dev_attributes; @@ -939,6 +917,58 @@ static struct attribute *hotkey_mask_attributes[] = { static int __init hotkey_init(struct ibm_init_struct *iibm) { + + static u16 ibm_keycode_map[] __initdata = { + /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ + KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, + KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, + KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, + /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ + KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ + KEY_UNKNOWN, /* 0x0D: FN+INSERT */ + KEY_UNKNOWN, /* 0x0E: FN+DELETE */ + KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ + /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ + KEY_RESERVED, /* 0x10: FN+END (brightness down) */ + KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ + KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ + KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ + KEY_RESERVED, /* 0x14: VOLUME UP */ + KEY_RESERVED, /* 0x15: VOLUME DOWN */ + KEY_RESERVED, /* 0x16: MUTE */ + KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ + /* (assignments unknown, please report if found) */ + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + }; + static u16 lenovo_keycode_map[] __initdata = { + /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ + KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, + KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, + KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, + /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ + KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ + KEY_UNKNOWN, /* 0x0D: FN+INSERT */ + KEY_UNKNOWN, /* 0x0E: FN+DELETE */ + KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ + /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ + KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ + KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ + KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ + KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ + KEY_RESERVED, /* 0x14: VOLUME UP */ + KEY_RESERVED, /* 0x15: VOLUME DOWN */ + KEY_RESERVED, /* 0x16: MUTE */ + KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ + /* (assignments unknown, please report if found) */ + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, + }; + +#define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) +#define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) +#define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) + int res, i; int status; @@ -1003,6 +1033,27 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) if (res) return res; + /* Set up key map */ + + hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, + GFP_KERNEL); + if (!hotkey_keycode_map) { + printk(IBM_ERR "failed to allocate memory for key map\n"); + return -ENOMEM; + } + + if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { + dbg_printk(TPACPI_DBG_INIT, + "using Lenovo default hot key map\n"); + memcpy(hotkey_keycode_map, &lenovo_keycode_map, + TPACPI_HOTKEY_MAP_SIZE); + } else { + dbg_printk(TPACPI_DBG_INIT, + "using IBM default hot key map\n"); + memcpy(hotkey_keycode_map, &ibm_keycode_map, + TPACPI_HOTKEY_MAP_SIZE); + } + #ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED for (i = 0; i < 12; i++) hotkey_keycode_map[i] = KEY_UNKNOWN; @@ -1011,10 +1062,10 @@ static int __init hotkey_init(struct ibm_init_struct *iibm) set_bit(EV_KEY, tpacpi_inputdev->evbit); set_bit(EV_MSC, tpacpi_inputdev->evbit); set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); - tpacpi_inputdev->keycodesize = sizeof(hotkey_keycode_map[0]); - tpacpi_inputdev->keycodemax = ARRAY_SIZE(hotkey_keycode_map); - tpacpi_inputdev->keycode = &hotkey_keycode_map; - for (i = 0; i < ARRAY_SIZE(hotkey_keycode_map); i++) { + tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; + tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; + tpacpi_inputdev->keycode = hotkey_keycode_map; + for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { if (hotkey_keycode_map[i] != KEY_RESERVED) { set_bit(hotkey_keycode_map[i], tpacpi_inputdev->keybit); @@ -4618,7 +4669,9 @@ static int __init thinkpad_acpi_module_init(void) tpacpi_inputdev->name = "ThinkPad Extra Buttons"; tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0"; tpacpi_inputdev->id.bustype = BUS_HOST; - tpacpi_inputdev->id.vendor = TPACPI_HKEY_INPUT_VENDOR; + tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? + thinkpad_id.vendor : + PCI_VENDOR_ID_IBM; tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; } -- cgit v1.2.2 From a8fba3da3d11d808137be7ebeb3b6938a42f011f Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:45 -0300 Subject: ACPI: thinkpad-acpi: make sure DSDT TMPx readings don't return +128 We get +128 instead of -128 from the DSDT TMPx methods, due to errors when converting a EC byte return that is a s8 to an ACPI handler return that is an int. Fix it once and for all, by clamping acceptable temperature readings from DSDT TMPx so that anything outside the [-127,+127] range is converted to TP_EC_THERMAL_TMP_NA (-128). Signed-off-by: Henrique de Moraes Holschuh Cc: Michael Olbrich Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 623d36fd8d..f74d7d600d 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -2853,6 +2853,8 @@ static int thermal_get_sensor(int idx, s32 *value) snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); if (!acpi_evalf(ec_handle, &t, tmpi, "d")) return -EIO; + if (t > 127 || t < -127) + t = TP_EC_THERMAL_TMP_NA; *value = t * 1000; return 0; } -- cgit v1.2.2 From 3d6f99ca00ccf861305fd8630a21f2e696886708 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:46 -0300 Subject: ACPI: thinkpad-acpi: make EC-based thermal readings non-experimental Reading the 16 thermal sensors directly from the EC has been stable for about one year, in all supported ThinkPad models. Remove its "experimental" label. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 18 +++++------------- drivers/misc/thinkpad_acpi.c | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 5d827ded34..3eb949e14a 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -710,23 +710,15 @@ Temperature sensors procfs: /proc/acpi/ibm/thermal sysfs device attributes: (hwmon) temp*_input -Most ThinkPads include six or more separate temperature sensors but -only expose the CPU temperature through the standard ACPI methods. -This feature shows readings from up to eight different sensors on older -ThinkPads, and it has experimental support for up to sixteen different -sensors on newer ThinkPads. - -EXPERIMENTAL: The 16-sensors feature is marked EXPERIMENTAL because the -implementation directly accesses hardware registers and may not work as -expected. USE WITH CAUTION! To use this feature, you need to supply the -experimental=1 parameter when loading the module. When EXPERIMENTAL -mode is enabled, reading the first 8 sensors on newer ThinkPads will -also use an new experimental thermal sensor access mode. +Most ThinkPads include six or more separate temperature sensors but only +expose the CPU temperature through the standard ACPI methods. This +feature shows readings from up to eight different sensors on older +ThinkPads, and up to sixteen different sensors on newer ThinkPads. For example, on the X40, a typical output may be: temperatures: 42 42 45 41 36 -128 33 -128 -EXPERIMENTAL: On the T43/p, a typical output may be: +On the T43/p, a typical output may be: temperatures: 48 48 36 52 38 -128 31 -128 48 52 48 -128 -128 -128 -128 -128 The mapping of thermal sensors to physical locations varies depending on diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index f74d7d600d..84a1000e4c 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -2709,7 +2709,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm) acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); - if (thinkpad_id.ec_model && experimental) { + if (thinkpad_id.ec_model) { /* * Direct EC access mode: sensors at registers * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for -- cgit v1.2.2 From c78d5c96bb65b71a54b7551b404fbaf4763ed6e4 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:47 -0300 Subject: ACPI: thinkpad-acpi: bump up version to 0.15 Name it thinkpad-acpi version 0.15. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- Documentation/thinkpad-acpi.txt | 8 ++++---- drivers/misc/thinkpad_acpi.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt index 3eb949e14a..6711fbcf40 100644 --- a/Documentation/thinkpad-acpi.txt +++ b/Documentation/thinkpad-acpi.txt @@ -1,11 +1,11 @@ ThinkPad ACPI Extras Driver - Version 0.14 - April 21st, 2007 + Version 0.15 + July 1st, 2007 Borislav Deianov - Henrique de Moraes Holschuh - http://ibm-acpi.sf.net/ + Henrique de Moraes Holschuh + http://ibm-acpi.sf.net/ This is a Linux driver for the IBM and Lenovo ThinkPad laptops. It diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 84a1000e4c..01bed937d3 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -21,7 +21,7 @@ * 02110-1301, USA. */ -#define IBM_VERSION "0.14" +#define IBM_VERSION "0.15" #define TPACPI_SYSFS_VERSION 0x010000 /* -- cgit v1.2.2 From f432255e936a892a6896e5032e2b4897423076f2 Mon Sep 17 00:00:00 2001 From: Henrique de Moraes Holschuh Date: Wed, 18 Jul 2007 23:45:48 -0300 Subject: ACPI: thinkpad-acpi: add locking to brightness subdriver The backlight class does all the locking needed for sysfs access, but offers no API to interface to that locking without an layer violation. Since we need to mutex-lock procfs access, implement in-driver locking for brightness. It will go away the day thinkpad-acpi procfs goes away, or the backlight class gives us a way to use its locks without a layer violation. Signed-off-by: Henrique de Moraes Holschuh Signed-off-by: Len Brown --- drivers/misc/thinkpad_acpi.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c index 01bed937d3..f15a58f740 100644 --- a/drivers/misc/thinkpad_acpi.c +++ b/drivers/misc/thinkpad_acpi.c @@ -3000,12 +3000,16 @@ static struct backlight_ops ibm_backlight_data = { .update_status = brightness_update_status, }; +static struct mutex brightness_mutex; + static int __init brightness_init(struct ibm_init_struct *iibm) { int b; vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); + mutex_init(&brightness_mutex); + if (!brightness_mode) { if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) brightness_mode = 2; @@ -3092,27 +3096,44 @@ static int brightness_get(struct backlight_device *bd) static int brightness_set(int value) { - int cmos_cmd, inc, i; - int current_value = brightness_get(NULL); + int cmos_cmd, inc, i, res; + int current_value; if (value > 7) return -EINVAL; + res = mutex_lock_interruptible(&brightness_mutex); + if (res < 0) + return res; + + current_value = brightness_get(NULL); + if (current_value < 0) { + res = current_value; + goto errout; + } + cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; inc = value > current_value ? 1 : -1; + res = 0; for (i = current_value; i != value; i += inc) { if ((brightness_mode & 2) && - issue_thinkpad_cmos_command(cmos_cmd)) - return -EIO; + issue_thinkpad_cmos_command(cmos_cmd)) { + res = -EIO; + goto errout; + } if ((brightness_mode & 1) && - !acpi_ec_write(brightness_offset, i + inc)) - return -EIO; + !acpi_ec_write(brightness_offset, i + inc)) { + res = -EIO; + goto errout;; + } } - return 0; +errout: + mutex_unlock(&brightness_mutex); + return res; } static int brightness_read(char *p) -- cgit v1.2.2 From 044847e02d46c0a9430e19249fd68777bb1d3c98 Mon Sep 17 00:00:00 2001 From: Mattia Dongili Date: Mon, 16 Jul 2007 02:34:33 +0900 Subject: sony-laptop: add new SNC handlers - lid state: GLID - indicator lamp: GILS/SILS - multimedia bass gain: GMGB/CMGB Signed-off-by: Mattia Dongili Signed-off-by: Len Brown --- drivers/misc/sony-laptop.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c index 9623eaf4f8..0f378fe44c 100644 --- a/drivers/misc/sony-laptop.c +++ b/drivers/misc/sony-laptop.c @@ -487,6 +487,14 @@ SNC_HANDLE_NAMES(audiopower_set, "AZPW"); SNC_HANDLE_NAMES(lanpower_get, "GLNP"); SNC_HANDLE_NAMES(lanpower_set, "LNPW"); +SNC_HANDLE_NAMES(lidstate_get, "GLID"); + +SNC_HANDLE_NAMES(indicatorlamp_get, "GILS"); +SNC_HANDLE_NAMES(indicatorlamp_set, "SILS"); + +SNC_HANDLE_NAMES(gainbass_get, "GMGB"); +SNC_HANDLE_NAMES(gainbass_set, "CMGB"); + SNC_HANDLE_NAMES(PID_get, "GPID"); SNC_HANDLE_NAMES(CTR_get, "GCTR"); @@ -507,6 +515,12 @@ static struct sony_nc_value sony_nc_values[] = { boolean_validate, 0), SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set, boolean_validate, 1), + SNC_HANDLE(lidstate, snc_lidstate_get, NULL, + boolean_validate, 0), + SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set, + boolean_validate, 0), + SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set, + boolean_validate, 0), /* unknown methods */ SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1), SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1), -- cgit v1.2.2 From 8538c3686c895f9334a3c22997b51b5a82de7550 Mon Sep 17 00:00:00 2001 From: Mattia Dongili Date: Mon, 16 Jul 2007 02:34:34 +0900 Subject: sony-laptop: map wireless switch events to KEY_WLAN Signed-off-by: Mattia Dongili Signed-off-by: Len Brown --- drivers/misc/sony-laptop.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c index 0f378fe44c..142d660b46 100644 --- a/drivers/misc/sony-laptop.c +++ b/drivers/misc/sony-laptop.c @@ -177,6 +177,8 @@ static struct { { SONYPI_EVENT_BACK_PRESSED, KEY_BACK }, { SONYPI_EVENT_HELP_PRESSED, KEY_HELP }, { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM }, + { SONYPI_EVENT_WIRELESS_ON, KEY_WLAN }, + { SONYPI_EVENT_WIRELESS_OFF, KEY_WLAN }, { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB }, { 0, 0 }, }; -- cgit v1.2.2 From 6315fd1c9cd6870a253699f07c5ada85cfe8fecb Mon Sep 17 00:00:00 2001 From: Mattia Dongili Date: Mon, 16 Jul 2007 02:34:35 +0900 Subject: sony-laptop: Add support for recent Vaios Fn keys (C series for now) Recent Vaios (C, AR, N, FE) need some special initialization sequence to enable Fn keys interrupts through the Embedded Controller. Moreover Fn keys have to be decoded internally using ACPI methods to get the key code. Thus a new DMI table to add SNC init time callbacks and new mappings for model-specific key code to generic sony-laptop code have been added. Signed-off-by: Mattia Dongili Signed-off-by: Len Brown --- drivers/misc/sony-laptop.c | 107 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c index 142d660b46..43315be3dc 100644 --- a/drivers/misc/sony-laptop.c +++ b/drivers/misc/sony-laptop.c @@ -704,14 +704,108 @@ static struct backlight_ops sony_backlight_ops = { .get_brightness = sony_backlight_get_brightness, }; +/* + * New SNC-only Vaios event mapping to driver known keys + */ +struct sony_nc_event { + u8 data; + u8 event; +}; + +static struct sony_nc_event *sony_nc_events; + +/* Vaio C* --maybe also FE*, N* and AR* ?-- special init sequence + * for Fn keys + */ +static int sony_nc_C_enable(struct dmi_system_id *id) +{ + int result = 0; + + printk(KERN_NOTICE DRV_PFX "detected %s\n", id->ident); + + sony_nc_events = id->driver_data; + + if (acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x4, &result) < 0 + || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x2, &result) < 0 + || acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x10, &result) < 0 + || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x0, &result) < 0 + || acpi_callsetfunc(sony_nc_acpi_handle, "SN03", 0x2, &result) < 0 + || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x101, &result) < 0) { + printk(KERN_WARNING DRV_PFX "failed to initialize SNC, some " + "functionalities may be missing\n"); + return 1; + } + return 0; +} + +static struct sony_nc_event sony_C_events[] = { + { 0x81, SONYPI_EVENT_FNKEY_F1 }, + { 0x01, SONYPI_EVENT_FNKEY_RELEASED }, + { 0x85, SONYPI_EVENT_FNKEY_F5 }, + { 0x05, SONYPI_EVENT_FNKEY_RELEASED }, + { 0x86, SONYPI_EVENT_FNKEY_F6 }, + { 0x06, SONYPI_EVENT_FNKEY_RELEASED }, + { 0x87, SONYPI_EVENT_FNKEY_F7 }, + { 0x07, SONYPI_EVENT_FNKEY_RELEASED }, + { 0x8A, SONYPI_EVENT_FNKEY_F10 }, + { 0x0A, SONYPI_EVENT_FNKEY_RELEASED }, + { 0x8C, SONYPI_EVENT_FNKEY_F12 }, + { 0x0C, SONYPI_EVENT_FNKEY_RELEASED }, + { 0, 0 }, +}; + +/* SNC-only model map */ +struct dmi_system_id sony_nc_ids[] = { + { + .ident = "Sony Vaio C Series", + .callback = sony_nc_C_enable, + .driver_data = sony_C_events, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-C"), + }, + }, + { } +}; + /* * ACPI callbacks */ static void sony_acpi_notify(acpi_handle handle, u32 event, void *data) { - dprintk("sony_acpi_notify, event: %d\n", event); - sony_laptop_report_input_event(event); - acpi_bus_generate_event(sony_nc_acpi_device, 1, event); + struct sony_nc_event *evmap; + u32 ev = event; + int result; + + if (ev == 0x92) { + /* read the key pressed from EC.GECR + * A call to SN07 with 0x0202 will do it as well respecting + * the current protocol on different OSes + * + * Note: the path for GECR may be + * \_SB.PCI0.LPCB.EC (C, FE, AR, N and friends) + * \_SB.PCI0.PIB.EC0 (VGN-FR notifications are sent directly, no GECR) + * + * TODO: we may want to do the same for the older GHKE -need + * dmi list- so this snippet may become one more callback. + */ + if (acpi_callsetfunc(handle, "SN07", 0x0202, &result) < 0) + dprintk("sony_acpi_notify, unable to decode event 0x%.2x\n", ev); + else + ev = result & 0xFF; + } + + if (sony_nc_events) + for (evmap = sony_nc_events; evmap->event; evmap++) { + if (evmap->data == ev) { + ev = evmap->event; + break; + } + } + + dprintk("sony_acpi_notify, event: 0x%.2x\n", ev); + sony_laptop_report_input_event(ev); + acpi_bus_generate_event(sony_nc_acpi_device, 1, ev); } static acpi_status sony_walk_callback(acpi_handle handle, u32 level, @@ -748,6 +842,10 @@ static int sony_nc_resume(struct acpi_device *device) break; } } + + /* re-initialize models with specific requirements */ + dmi_check_system(sony_nc_ids); + return 0; } @@ -811,6 +909,9 @@ static int sony_nc_add(struct acpi_device *device) } + /* initialize models with specific requirements */ + dmi_check_system(sony_nc_ids); + result = sony_pf_add(); if (result) goto outbacklight; -- cgit v1.2.2 From b25b732a16e4e035247fa729f931ed173f9fc8e2 Mon Sep 17 00:00:00 2001 From: Mattia Dongili Date: Mon, 16 Jul 2007 02:34:36 +0900 Subject: sony-laptop: Invoke _INI for SNC devices that provide it Signed-off-by: Mattia Dongili Signed-off-by: Len Brown --- drivers/misc/sony-laptop.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c index 43315be3dc..5300cad9cd 100644 --- a/drivers/misc/sony-laptop.c +++ b/drivers/misc/sony-laptop.c @@ -864,6 +864,15 @@ static int sony_nc_add(struct acpi_device *device) sony_nc_acpi_handle = device->handle; + /* read device status */ + result = acpi_bus_get_status(device); + /* bail IFF the above call was successful and the device is not present */ + if (!result && !device->status.present) { + dprintk("Device not present\n"); + result = -ENODEV; + goto outwalk; + } + if (debug) { status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle, 1, sony_walk_callback, NULL, NULL); @@ -874,6 +883,15 @@ static int sony_nc_add(struct acpi_device *device) } } + /* try to _INI the device if such method exists (ACPI spec 3.0-6.5.1 + * should be respected as we already checked for the device presence above */ + if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, METHOD_NAME__INI, &handle))) { + dprintk("Invoking _INI\n"); + if (ACPI_FAILURE(acpi_evaluate_object(sony_nc_acpi_handle, METHOD_NAME__INI, + NULL, NULL))) + dprintk("_INI Method failed\n"); + } + /* setup input devices and helper fifo */ result = sony_laptop_setup_input(); if (result) { @@ -886,7 +904,7 @@ static int sony_nc_add(struct acpi_device *device) ACPI_DEVICE_NOTIFY, sony_acpi_notify, NULL); if (ACPI_FAILURE(status)) { - printk(KERN_WARNING DRV_PFX "unable to install notify handler\n"); + printk(KERN_WARNING DRV_PFX "unable to install notify handler (%u)\n", status); result = -ENODEV; goto outinput; } -- cgit v1.2.2 From bc57f865fa2282ad2b7efe02da0a752e602e982e Mon Sep 17 00:00:00 2001 From: Mattia Dongili Date: Fri, 20 Jul 2007 02:01:57 +0900 Subject: sony-laptop: Make the driver use MSC_SCAN and a setkeycode and getkeycode key table. The following is the only way I could think of to hide some events as per Dmitry suggestions while still using the default {set,get}keycode implementation. Make the driver use MSC_SCAN and a setkeycode and getkeycode key table. Cc: Dmitry Torokhov Signed-off-by: Richard Hughes Signed-off-by: Mattia Dongili Signed-off-by: Len Brown --- drivers/misc/sony-laptop.c | 190 +++++++++++++++++++++++++++++++++------------ 1 file changed, 140 insertions(+), 50 deletions(-) diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c index 5300cad9cd..af69b3bd01 100644 --- a/drivers/misc/sony-laptop.c +++ b/drivers/misc/sony-laptop.c @@ -142,45 +142,124 @@ struct sony_laptop_keypress { int key; }; -/* Correspondance table between sonypi events and input layer events */ -static struct { - int sonypiev; - int inputev; -} sony_laptop_inputkeys[] = { - { SONYPI_EVENT_CAPTURE_PRESSED, KEY_CAMERA }, - { SONYPI_EVENT_FNKEY_ONLY, KEY_FN }, - { SONYPI_EVENT_FNKEY_ESC, KEY_FN_ESC }, - { SONYPI_EVENT_FNKEY_F1, KEY_FN_F1 }, - { SONYPI_EVENT_FNKEY_F2, KEY_FN_F2 }, - { SONYPI_EVENT_FNKEY_F3, KEY_FN_F3 }, - { SONYPI_EVENT_FNKEY_F4, KEY_FN_F4 }, - { SONYPI_EVENT_FNKEY_F5, KEY_FN_F5 }, - { SONYPI_EVENT_FNKEY_F6, KEY_FN_F6 }, - { SONYPI_EVENT_FNKEY_F7, KEY_FN_F7 }, - { SONYPI_EVENT_FNKEY_F8, KEY_FN_F8 }, - { SONYPI_EVENT_FNKEY_F9, KEY_FN_F9 }, - { SONYPI_EVENT_FNKEY_F10, KEY_FN_F10 }, - { SONYPI_EVENT_FNKEY_F11, KEY_FN_F11 }, - { SONYPI_EVENT_FNKEY_F12, KEY_FN_F12 }, - { SONYPI_EVENT_FNKEY_1, KEY_FN_1 }, - { SONYPI_EVENT_FNKEY_2, KEY_FN_2 }, - { SONYPI_EVENT_FNKEY_D, KEY_FN_D }, - { SONYPI_EVENT_FNKEY_E, KEY_FN_E }, - { SONYPI_EVENT_FNKEY_F, KEY_FN_F }, - { SONYPI_EVENT_FNKEY_S, KEY_FN_S }, - { SONYPI_EVENT_FNKEY_B, KEY_FN_B }, - { SONYPI_EVENT_BLUETOOTH_PRESSED, KEY_BLUE }, - { SONYPI_EVENT_BLUETOOTH_ON, KEY_BLUE }, - { SONYPI_EVENT_PKEY_P1, KEY_PROG1 }, - { SONYPI_EVENT_PKEY_P2, KEY_PROG2 }, - { SONYPI_EVENT_PKEY_P3, KEY_PROG3 }, - { SONYPI_EVENT_BACK_PRESSED, KEY_BACK }, - { SONYPI_EVENT_HELP_PRESSED, KEY_HELP }, - { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM }, - { SONYPI_EVENT_WIRELESS_ON, KEY_WLAN }, - { SONYPI_EVENT_WIRELESS_OFF, KEY_WLAN }, - { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB }, - { 0, 0 }, +/* Correspondance table between sonypi events + * and input layer indexes in the keymap + */ +static int sony_laptop_input_index[] = { + -1, /* no event */ + -1, /* SONYPI_EVENT_JOGDIAL_DOWN */ + -1, /* SONYPI_EVENT_JOGDIAL_UP */ + -1, /* SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */ + -1, /* SONYPI_EVENT_JOGDIAL_UP_PRESSED */ + -1, /* SONYPI_EVENT_JOGDIAL_PRESSED */ + -1, /* SONYPI_EVENT_JOGDIAL_RELEASED */ + 0, /* SONYPI_EVENT_CAPTURE_PRESSED */ + 1, /* SONYPI_EVENT_CAPTURE_RELEASED */ + 2, /* SONYPI_EVENT_CAPTURE_PARTIALPRESSED */ + 3, /* SONYPI_EVENT_CAPTURE_PARTIALRELEASED */ + 4, /* SONYPI_EVENT_FNKEY_ESC */ + 5, /* SONYPI_EVENT_FNKEY_F1 */ + 6, /* SONYPI_EVENT_FNKEY_F2 */ + 7, /* SONYPI_EVENT_FNKEY_F3 */ + 8, /* SONYPI_EVENT_FNKEY_F4 */ + 9, /* SONYPI_EVENT_FNKEY_F5 */ + 10, /* SONYPI_EVENT_FNKEY_F6 */ + 11, /* SONYPI_EVENT_FNKEY_F7 */ + 12, /* SONYPI_EVENT_FNKEY_F8 */ + 13, /* SONYPI_EVENT_FNKEY_F9 */ + 14, /* SONYPI_EVENT_FNKEY_F10 */ + 15, /* SONYPI_EVENT_FNKEY_F11 */ + 16, /* SONYPI_EVENT_FNKEY_F12 */ + 17, /* SONYPI_EVENT_FNKEY_1 */ + 18, /* SONYPI_EVENT_FNKEY_2 */ + 19, /* SONYPI_EVENT_FNKEY_D */ + 20, /* SONYPI_EVENT_FNKEY_E */ + 21, /* SONYPI_EVENT_FNKEY_F */ + 22, /* SONYPI_EVENT_FNKEY_S */ + 23, /* SONYPI_EVENT_FNKEY_B */ + 24, /* SONYPI_EVENT_BLUETOOTH_PRESSED */ + 25, /* SONYPI_EVENT_PKEY_P1 */ + 26, /* SONYPI_EVENT_PKEY_P2 */ + 27, /* SONYPI_EVENT_PKEY_P3 */ + 28, /* SONYPI_EVENT_BACK_PRESSED */ + -1, /* SONYPI_EVENT_LID_CLOSED */ + -1, /* SONYPI_EVENT_LID_OPENED */ + 29, /* SONYPI_EVENT_BLUETOOTH_ON */ + 30, /* SONYPI_EVENT_BLUETOOTH_OFF */ + 31, /* SONYPI_EVENT_HELP_PRESSED */ + 32, /* SONYPI_EVENT_FNKEY_ONLY */ + 33, /* SONYPI_EVENT_JOGDIAL_FAST_DOWN */ + 34, /* SONYPI_EVENT_JOGDIAL_FAST_UP */ + 35, /* SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */ + 36, /* SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */ + 37, /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN */ + 38, /* SONYPI_EVENT_JOGDIAL_VFAST_UP */ + 39, /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */ + 40, /* SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */ + 41, /* SONYPI_EVENT_ZOOM_PRESSED */ + 42, /* SONYPI_EVENT_THUMBPHRASE_PRESSED */ + 43, /* SONYPI_EVENT_MEYE_FACE */ + 44, /* SONYPI_EVENT_MEYE_OPPOSITE */ + 45, /* SONYPI_EVENT_MEMORYSTICK_INSERT */ + 46, /* SONYPI_EVENT_MEMORYSTICK_EJECT */ + -1, /* SONYPI_EVENT_ANYBUTTON_RELEASED */ + -1, /* SONYPI_EVENT_BATTERY_INSERT */ + -1, /* SONYPI_EVENT_BATTERY_REMOVE */ + -1, /* SONYPI_EVENT_FNKEY_RELEASED */ + 47, /* SONYPI_EVENT_WIRELESS_ON */ + 48, /* SONYPI_EVENT_WIRELESS_OFF */ +}; + +static int sony_laptop_input_keycode_map[] = { + KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */ + KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */ + KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */ + KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */ + KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */ + KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */ + KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */ + KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */ + KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */ + KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */ + KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */ + KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */ + KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */ + KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */ + KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */ + KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */ + KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */ + KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */ + KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */ + KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */ + KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */ + KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */ + KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */ + KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */ + KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */ + KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */ + KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */ + KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */ + KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */ + KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */ + KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */ + KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */ + KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */ + KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */ + KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */ + KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */ + KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */ + KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */ + KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */ + KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */ + KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */ + KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */ + BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */ + KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */ + KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */ + KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */ + KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */ + KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */ + KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */ }; /* release buttons after a short delay if pressed */ @@ -204,7 +283,6 @@ static void sony_laptop_report_input_event(u8 event) struct input_dev *jog_dev = sony_laptop_input.jog_dev; struct input_dev *key_dev = sony_laptop_input.key_dev; struct sony_laptop_keypress kp = { NULL }; - int i; if (event == SONYPI_EVENT_FNKEY_RELEASED) { /* Nothing, not all VAIOs generate this event */ @@ -233,17 +311,22 @@ static void sony_laptop_report_input_event(u8 event) break; default: - for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++) - if (event == sony_laptop_inputkeys[i].sonypiev) { + if (event > ARRAY_SIZE (sony_laptop_input_keycode_map)) { + dprintk("sony_laptop_report_input_event, event not known: %d\n", event); + break; + } + if (sony_laptop_input_index[event] != -1) { + kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]]; + if (kp.key != KEY_UNKNOWN) kp.dev = key_dev; - kp.key = sony_laptop_inputkeys[i].inputev; - break; - } + } break; } if (kp.dev) { input_report_key(kp.dev, kp.key, 1); + /* we emit the scancode so we can always remap the key */ + input_event(kp.dev, EV_MSC, MSC_SCAN, event); input_sync(kp.dev); kfifo_put(sony_laptop_input.fifo, (unsigned char *)&kp, sizeof(kp)); @@ -298,11 +381,18 @@ static int sony_laptop_setup_input(void) key_dev->id.vendor = PCI_VENDOR_ID_SONY; /* Initialize the Input Drivers: special keys */ - key_dev->evbit[0] = BIT(EV_KEY); - for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++) - if (sony_laptop_inputkeys[i].inputev) - set_bit(sony_laptop_inputkeys[i].inputev, - key_dev->keybit); + set_bit(EV_KEY, key_dev->evbit); + set_bit(EV_MSC, key_dev->evbit); + set_bit(MSC_SCAN, key_dev->mscbit); + key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]); + key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map); + key_dev->keycode = &sony_laptop_input_keycode_map; + for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) { + if (sony_laptop_input_keycode_map[i] != KEY_RESERVED) { + set_bit(sony_laptop_input_keycode_map[i], + key_dev->keybit); + } + } error = input_register_device(key_dev); if (error) -- cgit v1.2.2 From 89892d153d0d46018241afc7944910912bcd9688 Mon Sep 17 00:00:00 2001 From: Mattia Dongili Date: Mon, 16 Jul 2007 02:34:38 +0900 Subject: sony-laptop: Add Vaio FE to the special init sequence The Vaio FE series uses the same sequence as Vaio C series Signed-off-by: Mattia Dongili Signed-off-by: Len Brown --- drivers/misc/sony-laptop.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c index af69b3bd01..85969c85cd 100644 --- a/drivers/misc/sony-laptop.c +++ b/drivers/misc/sony-laptop.c @@ -846,6 +846,15 @@ static struct sony_nc_event sony_C_events[] = { /* SNC-only model map */ struct dmi_system_id sony_nc_ids[] = { + { + .ident = "Sony Vaio FE Series", + .callback = sony_nc_C_enable, + .driver_data = sony_C_events, + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), + DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FE"), + }, + }, { .ident = "Sony Vaio C Series", .callback = sony_nc_C_enable, -- cgit v1.2.2 From 22a17780584173635dae11bb83884952b00e5181 Mon Sep 17 00:00:00 2001 From: Mattia Dongili Date: Mon, 16 Jul 2007 02:34:39 +0900 Subject: sony-laptop: Fix event reading in sony-laptop The rewritten event reading code from sonypi was absolutely wrong, this patche makes things functional for type2 and type1 models. Cc: Andrei Paskevich Signed-off-by: Mattia Dongili Signed-off-by: Len Brown --- drivers/misc/sony-laptop.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c index 85969c85cd..303e48ca0e 100644 --- a/drivers/misc/sony-laptop.c +++ b/drivers/misc/sony-laptop.c @@ -1142,7 +1142,9 @@ static struct acpi_driver sony_nc_driver = { #define SONYPI_DEVICE_TYPE2 0x00000002 #define SONYPI_DEVICE_TYPE3 0x00000004 -#define SONY_PIC_EV_MASK 0xff +#define SONYPI_TYPE1_OFFSET 0x04 +#define SONYPI_TYPE2_OFFSET 0x12 +#define SONYPI_TYPE3_OFFSET 0x12 struct sony_pic_ioport { struct acpi_resource_io io; @@ -1156,6 +1158,7 @@ struct sony_pic_irq { struct sony_pic_dev { int model; + u16 evport_offset; u8 camera_power; u8 bluetooth_power; u8 wwan_power; @@ -2233,20 +2236,17 @@ end: static irqreturn_t sony_pic_irq(int irq, void *dev_id) { int i, j; - u32 port_val = 0; u8 ev = 0; u8 data_mask = 0; u8 device_event = 0; struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id; - acpi_os_read_port(dev->cur_ioport->io.minimum, &port_val, - dev->cur_ioport->io.address_length); - ev = port_val & SONY_PIC_EV_MASK; - data_mask = 0xff & (port_val >> (dev->cur_ioport->io.address_length - 8)); + ev = inb_p(dev->cur_ioport->io.minimum); + data_mask = inb_p(dev->cur_ioport->io.minimum + dev->evport_offset); - dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n", - port_val, ev, data_mask, dev->cur_ioport->io.minimum); + dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n", + ev, data_mask, dev->cur_ioport->io.minimum, dev->evport_offset); if (ev == 0x00 || ev == 0xff) return IRQ_HANDLED; @@ -2337,6 +2337,20 @@ static int sony_pic_add(struct acpi_device *device) spic_dev.model = sony_pic_detect_device_type(); mutex_init(&spic_dev.lock); + /* model specific characteristics */ + switch(spic_dev.model) { + case SONYPI_DEVICE_TYPE1: + spic_dev.evport_offset = SONYPI_TYPE1_OFFSET; + break; + case SONYPI_DEVICE_TYPE3: + spic_dev.evport_offset = SONYPI_TYPE3_OFFSET; + break; + case SONYPI_DEVICE_TYPE2: + default: + spic_dev.evport_offset = SONYPI_TYPE2_OFFSET; + break; + } + /* read _PRS resources */ result = sony_pic_possible_resources(device); if (result) { -- cgit v1.2.2 From 0dc070bb0242481a6100c95e5deaa07b267399a8 Mon Sep 17 00:00:00 2001 From: Dan Aloni Date: Mon, 9 Jul 2007 11:33:18 -0700 Subject: ACPI: drivers/acpi/pci_link.c: lower printk severity Signed-off-by: Dan Aloni Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/pci_link.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c index acc5947713..3448edd61d 100644 --- a/drivers/acpi/pci_link.c +++ b/drivers/acpi/pci_link.c @@ -733,7 +733,7 @@ static int acpi_pci_link_add(struct acpi_device *device) /* query and set link->irq.active */ acpi_pci_link_get_current(link); - printk(PREFIX "%s [%s] (IRQs", acpi_device_name(device), + printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device), acpi_device_bid(device)); for (i = 0; i < link->irq.possible_count; i++) { if (link->irq.active == link->irq.possible[i]) { -- cgit v1.2.2 From 4ebf83c8cf89ab13bc23e46b0fcb6178ca23b43c Mon Sep 17 00:00:00 2001 From: Dave Jones Date: Mon, 9 Jul 2007 11:33:14 -0700 Subject: ACPI: fix empty macros found by -Wextra ACPI has a ton of macros which make a bunch of empty if's when configured in non-debug mode. [lenb: The code it complaines about is functionally correct, so this patch is just to make -Wextra happier] #define DBG() if(...) DBG(); next_c_statement which turns into if(...) ; next_c_statement Signed-off-by: Dave Jones Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/glue.c | 2 +- include/acpi/acmacros.h | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index 41427a41f6..4893e256e3 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -16,7 +16,7 @@ #if ACPI_GLUE_DEBUG #define DBG(x...) printk(PREFIX x) #else -#define DBG(x...) +#define DBG(x...) do { } while(0) #endif static LIST_HEAD(bus_type_list); static DECLARE_RWSEM(bus_type_sem); diff --git a/include/acpi/acmacros.h b/include/acpi/acmacros.h index 8948a64618..e64a748bdd 100644 --- a/include/acpi/acmacros.h +++ b/include/acpi/acmacros.h @@ -599,26 +599,26 @@ #define ACPI_DEBUG_EXEC(a) #define ACPI_NORMAL_EXEC(a) a; -#define ACPI_DEBUG_DEFINE(a) -#define ACPI_DEBUG_ONLY_MEMBERS(a) -#define ACPI_FUNCTION_NAME(a) -#define ACPI_FUNCTION_TRACE(a) -#define ACPI_FUNCTION_TRACE_PTR(a,b) -#define ACPI_FUNCTION_TRACE_U32(a,b) -#define ACPI_FUNCTION_TRACE_STR(a,b) -#define ACPI_FUNCTION_EXIT -#define ACPI_FUNCTION_STATUS_EXIT(s) -#define ACPI_FUNCTION_VALUE_EXIT(s) -#define ACPI_FUNCTION_ENTRY() -#define ACPI_DUMP_STACK_ENTRY(a) -#define ACPI_DUMP_OPERANDS(a,b,c,d,e) -#define ACPI_DUMP_ENTRY(a,b) -#define ACPI_DUMP_TABLES(a,b) -#define ACPI_DUMP_PATHNAME(a,b,c,d) -#define ACPI_DUMP_RESOURCE_LIST(a) -#define ACPI_DUMP_BUFFER(a,b) -#define ACPI_DEBUG_PRINT(pl) -#define ACPI_DEBUG_PRINT_RAW(pl) +#define ACPI_DEBUG_DEFINE(a) do { } while(0) +#define ACPI_DEBUG_ONLY_MEMBERS(a) do { } while(0) +#define ACPI_FUNCTION_NAME(a) do { } while(0) +#define ACPI_FUNCTION_TRACE(a) do { } while(0) +#define ACPI_FUNCTION_TRACE_PTR(a,b) do { } while(0) +#define ACPI_FUNCTION_TRACE_U32(a,b) do { } while(0) +#define ACPI_FUNCTION_TRACE_STR(a,b) do { } while(0) +#define ACPI_FUNCTION_EXIT do { } while(0) +#define ACPI_FUNCTION_STATUS_EXIT(s) do { } while(0) +#define ACPI_FUNCTION_VALUE_EXIT(s) do { } while(0) +#define ACPI_FUNCTION_ENTRY() do { } while(0) +#define ACPI_DUMP_STACK_ENTRY(a) do { } while(0) +#define ACPI_DUMP_OPERANDS(a,b,c,d,e) do { } while(0) +#define ACPI_DUMP_ENTRY(a,b) do { } while(0) +#define ACPI_DUMP_TABLES(a,b) do { } while(0) +#define ACPI_DUMP_PATHNAME(a,b,c,d) do { } while(0) +#define ACPI_DUMP_RESOURCE_LIST(a) do { } while(0) +#define ACPI_DUMP_BUFFER(a,b) do { } while(0) +#define ACPI_DEBUG_PRINT(pl) do { } while(0) +#define ACPI_DEBUG_PRINT_RAW(pl) do { } while(0) #define return_VOID return #define return_ACPI_STATUS(s) return(s) -- cgit v1.2.2 From 9c977a453ed62396d067b75f3f272b3fb1ea3acc Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Fri, 20 Jul 2007 16:41:14 +0800 Subject: ACPI: export ACPI events via acpi_mc_group multicast group This is an incremental patch for the recent genetlink multicast changes. Now ACPI events are exported via generic netlink multicast group. Thanks for Johannes' help on developing this patch Signed-off-by: Zhang Rui Signed-off-by: Len Brown --- drivers/acpi/event.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c index de4def9b55..dfa5853b17 100644 --- a/drivers/acpi/event.c +++ b/drivers/acpi/event.c @@ -132,30 +132,19 @@ enum { }; #define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1) -#define ACPI_GENL_NAME "acpi_event" -#define ACPI_GENL_VERSION 0x01 +#define ACPI_GENL_FAMILY_NAME "acpi_event" +#define ACPI_GENL_VERSION 0x01 +#define ACPI_GENL_MCAST_GROUP_NAME "acpi_mc_group" static struct genl_family acpi_event_genl_family = { .id = GENL_ID_GENERATE, - .name = ACPI_GENL_NAME, + .name = ACPI_GENL_FAMILY_NAME, .version = ACPI_GENL_VERSION, .maxattr = ACPI_GENL_ATTR_MAX, }; -/* .doit: standard command callback */ -static int acpi_genl_cmd_event(struct sk_buff *skb, struct genl_info *info) -{ - struct acpi_genl_event *event = info->userhdr; - - if (!event) - ACPI_DEBUG_PRINT((ACPI_DB_WARN, "ACPI event: NULL\n")); - - return 0; -} - -static struct genl_ops acpi_event_genl_ops = { - .cmd = ACPI_GENL_CMD_EVENT, - .doit = acpi_genl_cmd_event, +static struct genl_multicast_group acpi_event_mcgrp = { + .name = ACPI_GENL_MCAST_GROUP_NAME, }; int acpi_bus_generate_genetlink_event(struct acpi_device *device, @@ -215,7 +204,7 @@ int acpi_bus_generate_genetlink_event(struct acpi_device *device, } result = - genlmsg_multicast(skb, 0, acpi_event_genl_family.id, GFP_ATOMIC); + genlmsg_multicast(skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC); if (result) ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Failed to send a Genetlink message!\n")); @@ -230,8 +219,8 @@ static int acpi_event_genetlink_init(void) if (result) return result; - result = - genl_register_ops(&acpi_event_genl_family, &acpi_event_genl_ops); + result = genl_register_mc_group(&acpi_event_genl_family, + &acpi_event_mcgrp); if (result) genl_unregister_family(&acpi_event_genl_family); -- cgit v1.2.2 From 7a9b9068b8c7b526894904c0b9b90354825b8fbd Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Fri, 13 Jul 2007 13:42:47 +0800 Subject: ACPI: update feature-removal-schedule.txt, /sys/firmware/acpi/namespace is gone The /sys/firmware/acpi/namespace has already been removed in 2.6.21. Signed-off-by: Zhang Rui Signed-off-by: Len Brown --- Documentation/feature-removal-schedule.txt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index 49ae1ea9e8..22fe37eca4 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt @@ -227,20 +227,6 @@ Who: Venkatesh Pallipadi --------------------------- -What: /sys/firmware/acpi/namespace -When: 2.6.21 -Why: The ACPI namespace is effectively the symbol list for - the BIOS. The device names are completely arbitrary - and have no place being exposed to user-space. - - For those interested in the BIOS ACPI namespace, - the BIOS can be extracted and disassembled with acpidump - and iasl as documented in the pmtools package here: - http://ftp.kernel.org/pub/linux/kernel/people/lenb/acpi/utils -Who: Len Brown - ---------------------------- - What: ACPI procfs interface When: July 2007 Why: After ACPI sysfs conversion, ACPI attributes will be duplicated -- cgit v1.2.2 From 8b8eb7d8cfc6cd95ed00cd58754e8493322505bd Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Wed, 18 Jul 2007 17:23:24 +0800 Subject: ACPI: update ACPI proc I/F removal schedule ACPI sysfs conversion is not finished yet and some user space tools still depend on the ACPI proc I/F. We plan to finish all the sysfs conversion by January 2008 and remove the ACPI proc I/F in July 2008. Signed-off-by: Zhang Rui Signed-off-by: Len Brown --- Documentation/feature-removal-schedule.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index 22fe37eca4..769862197a 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt @@ -228,9 +228,10 @@ Who: Venkatesh Pallipadi --------------------------- What: ACPI procfs interface -When: July 2007 -Why: After ACPI sysfs conversion, ACPI attributes will be duplicated - in sysfs and the ACPI procfs interface should be removed. +When: July 2008 +Why: ACPI sysfs conversion should be finished by January 2008. + ACPI procfs interface will be removed in July 2008 so that + there is enough time for the user space to catch up. Who: Zhang Rui --------------------------- -- cgit v1.2.2 From 798d91039849486c7a4f1a458a5680cb55a65408 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 31 May 2007 17:20:39 +0200 Subject: ACPI: create CONFIG_ACPI_DEBUG_FUNC_TRACE Split ACPI_DEBUG into function trace enabled and not enabled. Function trace is most of the ACPI_DEBUG costs, but is not much of use for kernel ACPI debugging. Size of kernel image increased on test compile: + 48k (Full ACPI_DEBUG) + 35k (ACPI_DEBUG with function trace compiled out) Performance without function trace is also much better. Also remove ACPI_LV_DEBUG_OBJECT from default debug level as a lot vendors let Store (value, debug) in their code and this might confuse users when it pops up in syslog. Signed-off-by: Thomas Renninger Signed-off-by: Len Brown --- drivers/acpi/Kconfig | 8 ++++++++ include/acpi/acmacros.h | 23 +++++++++++++++++++++++ include/acpi/acoutput.h | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 139f41f033..1121a1f4b5 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -280,6 +280,14 @@ config ACPI_DEBUG of verbosity. Saying Y enables these statements. This will increase your kernel size by around 50K. +config ACPI_DEBUG_FUNC_TRACE + bool "Additionally enable ACPI function tracing" + default n + depends on ACPI_DEBUG + help + ACPI Debug Statements slow down ACPI processing. Function trace + is about half of the penalty and is rarely useful. + config ACPI_EC bool default y diff --git a/include/acpi/acmacros.h b/include/acpi/acmacros.h index 8948a64618..c22f6da6d3 100644 --- a/include/acpi/acmacros.h +++ b/include/acpi/acmacros.h @@ -486,6 +486,8 @@ #define ACPI_FUNCTION_NAME(name) #endif +#ifdef DEBUG_FUNC_TRACE + #define ACPI_FUNCTION_TRACE(a) ACPI_FUNCTION_NAME(a) \ acpi_ut_trace(ACPI_DEBUG_PARAMETERS) #define ACPI_FUNCTION_TRACE_PTR(a,b) ACPI_FUNCTION_NAME(a) \ @@ -563,6 +565,27 @@ #endif /* ACPI_SIMPLE_RETURN_MACROS */ +#else /* !DEBUG_FUNC_TRACE */ + +#define ACPI_FUNCTION_TRACE(a) +#define ACPI_FUNCTION_TRACE_PTR(a,b) +#define ACPI_FUNCTION_TRACE_U32(a,b) +#define ACPI_FUNCTION_TRACE_STR(a,b) +#define ACPI_FUNCTION_EXIT +#define ACPI_FUNCTION_STATUS_EXIT(s) +#define ACPI_FUNCTION_VALUE_EXIT(s) +#define ACPI_FUNCTION_TRACE(a) +#define ACPI_FUNCTION_ENTRY() + +#define return_VOID return +#define return_ACPI_STATUS(s) return(s) +#define return_VALUE(s) return(s) +#define return_UINT8(s) return(s) +#define return_UINT32(s) return(s) +#define return_PTR(s) return(s) + +#endif /* DEBUG_FUNC_TRACE */ + /* Conditional execution */ #define ACPI_DEBUG_EXEC(a) a diff --git a/include/acpi/acoutput.h b/include/acpi/acoutput.h index 7812267b57..c090a8b0bc 100644 --- a/include/acpi/acoutput.h +++ b/include/acpi/acoutput.h @@ -178,8 +178,8 @@ /* Defaults for debug_level, debug and normal */ -#define ACPI_DEBUG_DEFAULT (ACPI_LV_INIT | ACPI_LV_WARN | ACPI_LV_ERROR | ACPI_LV_DEBUG_OBJECT) -#define ACPI_NORMAL_DEFAULT (ACPI_LV_INIT | ACPI_LV_WARN | ACPI_LV_ERROR | ACPI_LV_DEBUG_OBJECT) +#define ACPI_DEBUG_DEFAULT (ACPI_LV_INIT | ACPI_LV_WARN | ACPI_LV_ERROR) +#define ACPI_NORMAL_DEFAULT (ACPI_LV_INIT | ACPI_LV_WARN | ACPI_LV_ERROR) #define ACPI_DEBUG_ALL (ACPI_LV_AML_DISASSEMBLE | ACPI_LV_ALL_EXCEPTIONS | ACPI_LV_ALL) #endif /* __ACOUTPUT_H__ */ -- cgit v1.2.2 From d4c5f047ae2a33296774e41abc2ac5c89283f736 Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Thu, 14 Jun 2007 17:43:07 +0800 Subject: ACPI: Populate /sys/firmware/acpi/tables/ The file name is the signature, such as DSDT, and the contents are the binary table image. Some tables, such as the SSDT, can have multiple instances. If just one, the file is SSDT, but if 3 instances, for example, it will be SSDT1, SSDT2, SSDT3 All static tables (besides teh RSDP and RSDT themselves are exported. Dynamic tables, such as SSDT op-regions that are not declared in the RSDT, will be added in a subsequent patch. Signed-off-by: Zhang Rui Signed-off-by: Len Brown --- drivers/acpi/system.c | 165 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 144 insertions(+), 21 deletions(-) diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c index 83a8d30979..edee2806e3 100644 --- a/drivers/acpi/system.c +++ b/drivers/acpi/system.c @@ -39,15 +39,12 @@ ACPI_MODULE_NAME("system"); #define ACPI_SYSTEM_CLASS "system" #define ACPI_SYSTEM_DEVICE_NAME "System" -#define ACPI_SYSTEM_FILE_INFO "info" -#define ACPI_SYSTEM_FILE_EVENT "event" -#define ACPI_SYSTEM_FILE_DSDT "dsdt" -#define ACPI_SYSTEM_FILE_FADT "fadt" /* * Make ACPICA version work as module param */ -static int param_get_acpica_version(char *buffer, struct kernel_param *kp) { +static int param_get_acpica_version(char *buffer, struct kernel_param *kp) +{ int result; result = sprintf(buffer, "%x", ACPI_CA_VERSION); @@ -57,10 +54,127 @@ static int param_get_acpica_version(char *buffer, struct kernel_param *kp) { module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); +/* -------------------------------------------------------------------------- + FS Interface (/sys) + -------------------------------------------------------------------------- */ +static LIST_HEAD(acpi_table_attr_list); +static struct kobject tables_kobj; + +struct acpi_table_attr { + struct bin_attribute attr; + char name[8]; + int instance; + struct list_head node; +}; + +static ssize_t acpi_table_show(struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t offset, size_t count) +{ + struct acpi_table_attr *table_attr = + container_of(bin_attr, struct acpi_table_attr, attr); + struct acpi_table_header *table_header = NULL; + acpi_status status; + ssize_t ret_count = count; + + status = + acpi_get_table(table_attr->name, table_attr->instance, + &table_header); + if (ACPI_FAILURE(status)) + return -ENODEV; + + if (offset >= table_header->length) { + ret_count = 0; + goto end; + } + + if (offset + ret_count > table_header->length) + ret_count = table_header->length - offset; + + memcpy(buf, ((char *)table_header) + offset, ret_count); + + end: + return ret_count; +} + +static void acpi_table_attr_init(struct acpi_table_attr *table_attr, + struct acpi_table_header *table_header) +{ + struct acpi_table_header *header = NULL; + struct acpi_table_attr *attr = NULL; + + memcpy(table_attr->name, table_header->signature, ACPI_NAME_SIZE); + + list_for_each_entry(attr, &acpi_table_attr_list, node) { + if (!memcmp(table_header->signature, attr->name, + ACPI_NAME_SIZE)) + if (table_attr->instance < attr->instance) + table_attr->instance = attr->instance; + } + table_attr->instance++; + + if (table_attr->instance > 1 || (table_attr->instance == 1 && + !acpi_get_table(table_header-> + signature, 2, + &header))) + sprintf(table_attr->name + 4, "%d", table_attr->instance); + + table_attr->attr.size = 0; + table_attr->attr.read = acpi_table_show; + table_attr->attr.attr.name = table_attr->name; + table_attr->attr.attr.mode = 0444; + table_attr->attr.attr.owner = THIS_MODULE; + + return; +} + +static int acpi_system_sysfs_init(void) +{ + struct acpi_table_attr *table_attr; + struct acpi_table_header *table_header = NULL; + int table_index = 0; + int result; + + tables_kobj.parent = &acpi_subsys.kobj; + kobject_set_name(&tables_kobj, "tables"); + result = kobject_register(&tables_kobj); + if (result) + return result; + + do { + result = acpi_get_table_by_index(table_index, &table_header); + if (!result) { + table_index++; + table_attr = NULL; + table_attr = + kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL); + if (!table_attr) + return -ENOMEM; + + acpi_table_attr_init(table_attr, table_header); + result = + sysfs_create_bin_file(&tables_kobj, + &table_attr->attr); + if (result) { + kfree(table_attr); + return result; + } else + list_add_tail(&table_attr->node, + &acpi_table_attr_list); + } + } while (!result); + + return 0; +} + /* -------------------------------------------------------------------------- FS Interface (/proc) -------------------------------------------------------------------------- */ #ifdef CONFIG_ACPI_PROCFS +#define ACPI_SYSTEM_FILE_INFO "info" +#define ACPI_SYSTEM_FILE_EVENT "event" +#define ACPI_SYSTEM_FILE_DSDT "dsdt" +#define ACPI_SYSTEM_FILE_FADT "fadt" static int acpi_system_read_info(struct seq_file *seq, void *offset) { @@ -80,7 +194,6 @@ static const struct file_operations acpi_system_info_ops = { .llseek = seq_lseek, .release = single_release, }; -#endif static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, loff_t *); @@ -97,13 +210,11 @@ acpi_system_read_dsdt(struct file *file, struct acpi_table_header *dsdt = NULL; ssize_t res; - status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt); if (ACPI_FAILURE(status)) return -ENODEV; - res = simple_read_from_buffer(buffer, count, ppos, - dsdt, dsdt->length); + res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length); return res; } @@ -123,28 +234,21 @@ acpi_system_read_fadt(struct file *file, struct acpi_table_header *fadt = NULL; ssize_t res; - status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt); if (ACPI_FAILURE(status)) return -ENODEV; - res = simple_read_from_buffer(buffer, count, ppos, - fadt, fadt->length); + res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length); return res; } -static int __init acpi_system_init(void) +static int acpi_system_procfs_init(void) { struct proc_dir_entry *entry; int error = 0; char *name; - - if (acpi_disabled) - return 0; - -#ifdef CONFIG_ACPI_PROCFS /* 'info' [R] */ name = ACPI_SYSTEM_FILE_INFO; entry = create_proc_entry(name, S_IRUGO, acpi_root_dir); @@ -153,7 +257,6 @@ static int __init acpi_system_init(void) else { entry->proc_fops = &acpi_system_info_ops; } -#endif /* 'dsdt' [R] */ name = ACPI_SYSTEM_FILE_DSDT; @@ -177,12 +280,32 @@ static int __init acpi_system_init(void) Error: remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); -#ifdef CONFIG_ACPI_PROCFS remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); -#endif error = -EFAULT; goto Done; } +#else +static int acpi_system_procfs_init(void) +{ + return 0; +} +#endif + +static int __init acpi_system_init(void) +{ + int result = 0; + + if (acpi_disabled) + return 0; + + result = acpi_system_procfs_init(); + if (result) + return result; + + result = acpi_system_sysfs_init(); + + return result; +} subsys_initcall(acpi_system_init); -- cgit v1.2.2