From 4b30fbca4f64bc70c59867ad5769c37efb587ff4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Fri, 21 May 2010 17:10:33 +0800 Subject: intel_menlow: fix memory leaks in error path This patch includes below fixes in error path: 1. fix a memory leak if device_create_file failed in intel_menlow_add_one_attribute 2. properly free added attributes before return error in intel_menlow_register_sensor error handler 3. properly call acpi_bus_unregister_driver before return error in intel_menlow_module_init Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_menlow.c b/drivers/platform/x86/intel_menlow.c index 2f795ce..eacd5da 100644 --- a/drivers/platform/x86/intel_menlow.c +++ b/drivers/platform/x86/intel_menlow.c @@ -53,6 +53,8 @@ MODULE_LICENSE("GPL"); #define MEMORY_ARG_CUR_BANDWIDTH 1 #define MEMORY_ARG_MAX_BANDWIDTH 0 +static void intel_menlow_unregister_sensor(void); + /* * GTHS returning 'n' would mean that [0,n-1] states are supported * In that case max_cstate would be n-1 @@ -406,8 +408,10 @@ static int intel_menlow_add_one_attribute(char *name, int mode, void *show, attr->handle = handle; result = device_create_file(dev, &attr->attr); - if (result) + if (result) { + kfree(attr); return result; + } mutex_lock(&intel_menlow_attr_lock); list_add_tail(&attr->node, &intel_menlow_attr_list); @@ -431,11 +435,11 @@ static acpi_status intel_menlow_register_sensor(acpi_handle handle, u32 lvl, /* _TZ must have the AUX0/1 methods */ status = acpi_get_handle(handle, GET_AUX0, &dummy); if (ACPI_FAILURE(status)) - goto not_found; + return (status == AE_NOT_FOUND) ? AE_OK : status; status = acpi_get_handle(handle, SET_AUX0, &dummy); if (ACPI_FAILURE(status)) - goto not_found; + return (status == AE_NOT_FOUND) ? AE_OK : status; result = intel_menlow_add_one_attribute("aux0", 0644, aux0_show, aux0_store, @@ -445,17 +449,19 @@ static acpi_status intel_menlow_register_sensor(acpi_handle handle, u32 lvl, status = acpi_get_handle(handle, GET_AUX1, &dummy); if (ACPI_FAILURE(status)) - goto not_found; + goto aux1_not_found; status = acpi_get_handle(handle, SET_AUX1, &dummy); if (ACPI_FAILURE(status)) - goto not_found; + goto aux1_not_found; result = intel_menlow_add_one_attribute("aux1", 0644, aux1_show, aux1_store, &thermal->device, handle); - if (result) + if (result) { + intel_menlow_unregister_sensor(); return AE_ERROR; + } /* * create the "dabney_enabled" attribute which means the user app @@ -465,14 +471,17 @@ static acpi_status intel_menlow_register_sensor(acpi_handle handle, u32 lvl, result = intel_menlow_add_one_attribute("bios_enabled", 0444, bios_enabled_show, NULL, &thermal->device, handle); - if (result) + if (result) { + intel_menlow_unregister_sensor(); return AE_ERROR; + } - not_found: + aux1_not_found: if (status == AE_NOT_FOUND) return AE_OK; - else - return status; + + intel_menlow_unregister_sensor(); + return status; } static void intel_menlow_unregister_sensor(void) @@ -513,8 +522,10 @@ static int __init intel_menlow_module_init(void) status = acpi_walk_namespace(ACPI_TYPE_THERMAL, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, intel_menlow_register_sensor, NULL, NULL, NULL); - if (ACPI_FAILURE(status)) + if (ACPI_FAILURE(status)) { + acpi_bus_unregister_driver(&intel_menlow_memory_driver); return -ENODEV; + } return 0; } -- cgit v0.10.2 From 751ae808f6b29803228609f51aa1ae057f5c576e Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 21 May 2010 16:18:09 +0200 Subject: x86 platform drivers: hp-wmi Reorder event id processing Event id 0x4 defines the hotkey event. No need (or even wrong) to query HPWMI_HOTKEY_QUERY if event id is != 0x4. Reorder the eventcode conditionals and use switch case instead of if/else. Use an enum for the event ids cases. Signed-off-by: Thomas Renninger Signed-off-by: Matthew Garrett CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 51c07a0..f1c1862 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -58,6 +58,12 @@ enum hp_wmi_radio { HPWMI_WWAN = 2, }; +enum hp_wmi_event_ids { + HPWMI_DOCK_EVENT = 1, + HPWMI_BEZEL_BUTTON = 4, + HPWMI_WIRELESS = 5, +}; + static int __devinit hp_wmi_bios_setup(struct platform_device *device); static int __exit hp_wmi_bios_remove(struct platform_device *device); static int hp_wmi_resume_handler(struct device *device); @@ -338,7 +344,7 @@ static void hp_wmi_notify(u32 value, void *context) struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; static struct key_entry *key; union acpi_object *obj; - int eventcode; + int eventcode, key_code; acpi_status status; status = wmi_get_event_data(value, &response); @@ -357,28 +363,32 @@ static void hp_wmi_notify(u32 value, void *context) eventcode = *((u8 *) obj->buffer.pointer); kfree(obj); - if (eventcode == 0x4) - eventcode = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, - 0); - key = hp_wmi_get_entry_by_scancode(eventcode); - if (key) { - switch (key->type) { - case KE_KEY: - input_report_key(hp_wmi_input_dev, - key->keycode, 1); - input_sync(hp_wmi_input_dev); - input_report_key(hp_wmi_input_dev, - key->keycode, 0); - input_sync(hp_wmi_input_dev); - break; - } - } else if (eventcode == 0x1) { + switch (eventcode) { + case HPWMI_DOCK_EVENT: input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, hp_wmi_tablet_state()); input_sync(hp_wmi_input_dev); - } else if (eventcode == 0x5) { + break; + case HPWMI_BEZEL_BUTTON: + key_code = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, + 0); + key = hp_wmi_get_entry_by_scancode(key_code); + if (key) { + switch (key->type) { + case KE_KEY: + input_report_key(hp_wmi_input_dev, + key->keycode, 1); + input_sync(hp_wmi_input_dev); + input_report_key(hp_wmi_input_dev, + key->keycode, 0); + input_sync(hp_wmi_input_dev); + break; + } + } + break; + case HPWMI_WIRELESS: if (wifi_rfkill) rfkill_set_states(wifi_rfkill, hp_wmi_get_sw_state(HPWMI_WIFI), @@ -391,9 +401,12 @@ static void hp_wmi_notify(u32 value, void *context) rfkill_set_states(wwan_rfkill, hp_wmi_get_sw_state(HPWMI_WWAN), hp_wmi_get_hw_state(HPWMI_WWAN)); - } else + break; + default: printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", eventcode); + break; + } } static int __init hp_wmi_input_setup(void) -- cgit v0.10.2 From da9a79ba5873b0f1d4dc7711ea6a96be6b69341e Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 21 May 2010 16:18:10 +0200 Subject: x86 platform drivers: hp-wmi Catch and log unkown event and key codes correctly Signed-off-by: Thomas Renninger Signed-off-by: Matthew Garrett CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index f1c1862..7b086dd 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -386,7 +386,9 @@ static void hp_wmi_notify(u32 value, void *context) input_sync(hp_wmi_input_dev); break; } - } + } else + printk(KERN_INFO "HP WMI: Unknown key code - 0x%x\n", + key_code); break; case HPWMI_WIRELESS: if (wifi_rfkill) @@ -403,8 +405,8 @@ static void hp_wmi_notify(u32 value, void *context) hp_wmi_get_hw_state(HPWMI_WWAN)); break; default: - printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", - eventcode); + printk(KERN_INFO "HP WMI: Unknown eventcode - %d\n", + eventcode); break; } } -- cgit v0.10.2 From a2806c6f00d851f11ef8725d78739d48a1ca2fe9 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 21 May 2010 16:18:11 +0200 Subject: x86 platform drivers: hp-wmi Use consistent prefix string for messages. Signed-off-by: Thomas Renninger Signed-off-by: Matthew Garrett CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 7b086dd..e04715a 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -52,6 +52,8 @@ MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); #define HPWMI_WIRELESS_QUERY 0x5 #define HPWMI_HOTKEY_QUERY 0xc +#define PREFIX "HP WMI: " + enum hp_wmi_radio { HPWMI_WIFI = 0, HPWMI_BLUETOOTH = 1, @@ -349,14 +351,14 @@ static void hp_wmi_notify(u32 value, void *context) status = wmi_get_event_data(value, &response); if (status != AE_OK) { - printk(KERN_INFO "hp-wmi: bad event status 0x%x\n", status); + printk(KERN_INFO PREFIX "bad event status 0x%x\n", status); return; } obj = (union acpi_object *)response.pointer; if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) { - printk(KERN_INFO "HP WMI: Unknown response received\n"); + printk(KERN_INFO PREFIX "Unknown response received\n"); kfree(obj); return; } @@ -387,7 +389,7 @@ static void hp_wmi_notify(u32 value, void *context) break; } } else - printk(KERN_INFO "HP WMI: Unknown key code - 0x%x\n", + printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n", key_code); break; case HPWMI_WIRELESS: @@ -405,7 +407,7 @@ static void hp_wmi_notify(u32 value, void *context) hp_wmi_get_hw_state(HPWMI_WWAN)); break; default: - printk(KERN_INFO "HP WMI: Unknown eventcode - %d\n", + printk(KERN_INFO PREFIX "Unknown eventcode - %d\n", eventcode); break; } -- cgit v0.10.2 From f6b2ff0821fb1b05a24beb6b343aa80e8a383a9e Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 21 May 2010 16:18:12 +0200 Subject: x86 platform drivers: hp-wmi Add media key 0x20e8 Signed-off-by: Thomas Renninger Signed-off-by: Matthew Garrett CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index e04715a..f3ae911 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -96,6 +96,7 @@ static struct key_entry hp_wmi_keymap[] = { {KE_KEY, 0x02, KEY_BRIGHTNESSUP}, {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, {KE_KEY, 0x20e6, KEY_PROG1}, + {KE_KEY, 0x20e8, KEY_MEDIA}, {KE_KEY, 0x2142, KEY_MEDIA}, {KE_KEY, 0x213b, KEY_INFO}, {KE_KEY, 0x2169, KEY_DIRECTION}, -- cgit v0.10.2 From 1bbdfd5961e83a1e3037d9362094bd09e0b066ab Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 21 May 2010 16:18:13 +0200 Subject: x86 platform drivers: hp-wmi Set placeholder for unimplemented events Rather than print unknown events when we know what caused them Signed-off-by: Thomas Renninger Signed-off-by: Matthew Garrett CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index f3ae911..cd44501 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -53,6 +53,7 @@ MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); #define HPWMI_HOTKEY_QUERY 0xc #define PREFIX "HP WMI: " +#define UNIMP "Unimplemented " enum hp_wmi_radio { HPWMI_WIFI = 0, @@ -62,8 +63,12 @@ enum hp_wmi_radio { enum hp_wmi_event_ids { HPWMI_DOCK_EVENT = 1, + HPWMI_PARK_HDD = 2, + HPWMI_SMART_ADAPTER = 3, HPWMI_BEZEL_BUTTON = 4, HPWMI_WIRELESS = 5, + HPWMI_CPU_BATTERY_THROTTLE = 6, + HPWMI_LOCK_SWITCH = 7, }; static int __devinit hp_wmi_bios_setup(struct platform_device *device); @@ -374,6 +379,10 @@ static void hp_wmi_notify(u32 value, void *context) hp_wmi_tablet_state()); input_sync(hp_wmi_input_dev); break; + case HPWMI_PARK_HDD: + break; + case HPWMI_SMART_ADAPTER: + break; case HPWMI_BEZEL_BUTTON: key_code = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, 0); @@ -407,6 +416,12 @@ static void hp_wmi_notify(u32 value, void *context) hp_wmi_get_sw_state(HPWMI_WWAN), hp_wmi_get_hw_state(HPWMI_WWAN)); break; + case HPWMI_CPU_BATTERY_THROTTLE: + printk(KERN_INFO PREFIX UNIMP "CPU throttle because of 3 Cell" + " battery event detected\n"); + break; + case HPWMI_LOCK_SWITCH: + break; default: printk(KERN_INFO PREFIX "Unknown eventcode - %d\n", eventcode); -- cgit v0.10.2 From 8dda6b0410cfc64642b2ed5b37987292f6321d0f Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 21 May 2010 16:41:43 +0200 Subject: x86 platform drivers: hp-wmi fix buffer size depending on ACPI version Depending on ACPI version (1.0 -> 32 bit) an integer could be 32 or 64 bit long. _WED internal concatenates two integers and the return value will be 8 byte (2* 32 bit) or 16 byte (2* 64 bit) long, depending on the ACPI version. Also the data send with the WMI event is defined to be splitted into: - Event ID -> 4 bytes - Event Data -> 4 bytes This gets messed up with new ACPI versions. But it's a HP BIOS bug that may get fixed in the future -> Support both, 16 and 8 byte _WED buffers. Also the wrong assumption that from the event data sent, only the first byte is relevant got cleaned up that it fits event_id/event_data as described above. Signed-off-by: Thomas Renninger CC: robert.moore@intel.com Signed-off-by: Matthew Garrett CC: platform-driver-x86@vger.kernel.org CC: linux-acpi@vger.kernel.org diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index cd44501..7ebe46f 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -352,7 +352,9 @@ static void hp_wmi_notify(u32 value, void *context) struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; static struct key_entry *key; union acpi_object *obj; - int eventcode, key_code; + u32 event_id, event_data; + int key_code; + u32 *location; acpi_status status; status = wmi_get_event_data(value, &response); @@ -363,15 +365,33 @@ static void hp_wmi_notify(u32 value, void *context) obj = (union acpi_object *)response.pointer; - if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) { - printk(KERN_INFO PREFIX "Unknown response received\n"); + if (obj || obj->type != ACPI_TYPE_BUFFER) { + printk(KERN_INFO "hp-wmi: Unknown response received %d\n", + obj->type); kfree(obj); return; } - eventcode = *((u8 *) obj->buffer.pointer); + /* + * Depending on ACPI version the concatenation of id and event data + * inside _WED function will result in a 8 or 16 byte buffer. + */ + location = (u32 *)obj->buffer.pointer; + if (obj->buffer.length == 8) { + event_id = *location; + event_data = *(location + 1); + } else if (obj->buffer.length == 16) { + event_id = *location; + event_data = *(location + 2); + } else { + printk(KERN_INFO "hp-wmi: Unknown buffer length %d\n", + obj->buffer.length); + kfree(obj); + return; + } kfree(obj); - switch (eventcode) { + + switch (event_id) { case HPWMI_DOCK_EVENT: input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); @@ -423,8 +443,8 @@ static void hp_wmi_notify(u32 value, void *context) case HPWMI_LOCK_SWITCH: break; default: - printk(KERN_INFO PREFIX "Unknown eventcode - %d\n", - eventcode); + printk(KERN_INFO PREFIX "Unknown event_id - %d - 0x%x\n", + event_id, event_data); break; } } -- cgit v0.10.2 From 6d96e00cef35036c513d342c4676d210b842880d Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 21 May 2010 16:42:40 +0200 Subject: X86 platform: hp-wmi Better match the HP WMI query interface - Improve error handling, by explictly return zero for success, error otherwise - WMI query command can have arbitrary input sized params - WMI query command can have specific output sized params (0, 4, 128,..) byte I like to go on here, but this is a rather intrusive change that should be looked at first. I am sure the one or other thing can be done better or there might be typo/bug somewhere. This did not get any testing yet, only compile tested. Next steps could be: - Eventually introduce hp_wmi_perform_{read,write}_query macros - Introduce new wireless query interface (0x1B) - more Signed-off-by: Thomas Renninger Signed-off-by: Matthew Garrett CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 7ebe46f..d81f4cf 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -80,13 +80,12 @@ struct bios_args { u32 command; u32 commandtype; u32 datasize; - u32 data; + char *data; }; struct bios_return { u32 sigpass; u32 return_code; - u32 value; }; struct key_entry { @@ -131,7 +130,27 @@ static struct platform_driver hp_wmi_driver = { .remove = hp_wmi_bios_remove, }; -static int hp_wmi_perform_query(int query, int write, int value) +/* + * hp_wmi_perform_query + * + * query: The commandtype -> What should be queried + * write: The command -> 0 read, 1 write, 3 ODM specific + * buffer: Buffer used as input and/or output + * buffersize: Size of buffer + * + * returns zero on success + * an HP WMI query specific error code (which is positive) + * -EINVAL if the query was not successful at all + * -EINVAL if the output buffer size exceeds buffersize + * + * Note: The buffersize must at least be the maximum of the input and output + * size. E.g. Battery info query (0x7) is defined to have 1 byte input + * and 128 byte output. The caller would do: + * buffer = kzalloc(128, GFP_KERNEL); + * ret = hp_wmi_perform_query(0x7, 0, buffer, 128) + */ +static int hp_wmi_perform_query(int query, int write, char *buffer, + int buffersize) { struct bios_return bios_return; acpi_status status; @@ -140,8 +159,8 @@ static int hp_wmi_perform_query(int query, int write, int value) .signature = 0x55434553, .command = write ? 0x2 : 0x1, .commandtype = query, - .datasize = write ? 0x4 : 0, - .data = value, + .datasize = buffersize, + .data = buffer, }; struct acpi_buffer input = { sizeof(struct bios_args), &args }; struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -158,54 +177,90 @@ static int hp_wmi_perform_query(int query, int write, int value) } bios_return = *((struct bios_return *)obj->buffer.pointer); + + if (bios_return.return_code) { + printk(KERN_WARNING PREFIX "Query %d returned %d\n", query, + bios_return.return_code); + kfree(obj); + return bios_return.return_code; + } + if (obj->buffer.length - sizeof(bios_return) > buffersize) { + kfree(obj); + return -EINVAL; + } + + memset(buffer, 0, buffersize); + memcpy(buffer, + ((char *)obj->buffer.pointer) + sizeof(struct bios_return), + obj->buffer.length - sizeof(bios_return)); kfree(obj); - if (bios_return.return_code > 0) - return bios_return.return_code * -1; - else - return bios_return.value; + return 0; } static int hp_wmi_display_state(void) { - return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0); + int state; + int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, (char *)&state, + sizeof(state)); + if (ret) + return -EINVAL; + return state; } static int hp_wmi_hddtemp_state(void) { - return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0); + int state; + int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, (char *)&state, + sizeof(state)); + if (ret) + return -EINVAL; + return state; } static int hp_wmi_als_state(void) { - return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0); + int state; + int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, (char *)&state, + sizeof(state)); + if (ret) + return -EINVAL; + return state; } static int hp_wmi_dock_state(void) { - int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0); + int state; + int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, (char *)&state, + sizeof(state)); - if (ret < 0) - return ret; + if (ret) + return -EINVAL; - return ret & 0x1; + return state & 0x1; } static int hp_wmi_tablet_state(void) { - int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0); - - if (ret < 0) + int state; + int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, (char *)&state, + sizeof(state)); + if (ret) return ret; - return (ret & 0x4) ? 1 : 0; + return (state & 0x4) ? 1 : 0; } static int hp_wmi_set_block(void *data, bool blocked) { enum hp_wmi_radio r = (enum hp_wmi_radio) data; int query = BIT(r + 8) | ((!blocked) << r); + int ret; - return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query); + ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, + (char *)&query, sizeof(query)); + if (ret) + return -EINVAL; + return 0; } static const struct rfkill_ops hp_wmi_rfkill_ops = { @@ -214,8 +269,13 @@ static const struct rfkill_ops hp_wmi_rfkill_ops = { static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) { - int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); - int mask = 0x200 << (r * 8); + int wireless; + int mask; + hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, + (char *)&wireless, sizeof(wireless)); + /* TBD: Pass error */ + + mask = 0x200 << (r * 8); if (wireless & mask) return false; @@ -225,8 +285,13 @@ static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) { - int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); - int mask = 0x800 << (r * 8); + int wireless; + int mask; + hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, + (char *)&wireless, sizeof(wireless)); + /* TBD: Pass error */ + + mask = 0x800 << (r * 8); if (wireless & mask) return false; @@ -283,7 +348,11 @@ static ssize_t set_als(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { u32 tmp = simple_strtoul(buf, NULL, 10); - hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp); + int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, (char *)&tmp, + sizeof(tmp)); + if (ret) + return -EINVAL; + return count; } @@ -353,7 +422,7 @@ static void hp_wmi_notify(u32 value, void *context) static struct key_entry *key; union acpi_object *obj; u32 event_id, event_data; - int key_code; + int key_code, ret; u32 *location; acpi_status status; @@ -404,8 +473,11 @@ static void hp_wmi_notify(u32 value, void *context) case HPWMI_SMART_ADAPTER: break; case HPWMI_BEZEL_BUTTON: - key_code = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, - 0); + ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, + (char *)&key_code, + sizeof(key_code)); + if (ret) + break; key = hp_wmi_get_entry_by_scancode(key_code); if (key) { switch (key->type) { @@ -503,7 +575,12 @@ static void cleanup_sysfs(struct platform_device *device) static int __devinit hp_wmi_bios_setup(struct platform_device *device) { int err; - int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); + int wireless; + + err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, (char *)&wireless, + sizeof(wireless)); + if (err) + return err; err = device_create_file(&device->dev, &dev_attr_display); if (err) -- cgit v0.10.2 From 0fc8f274aef03bbe85774ba30e75deb58e8a90ff Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Thu, 27 May 2010 18:32:15 +0200 Subject: drivers/platform/x86: Eliminate a NULL pointer dereference Give different error messages if device_enum is NULL or if its type field has the wrong value. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // @r exists@ expression E,E1; identifier f; statement S1,S2,S3; @@ if ((E == NULL && ...) || ...) { ... when != if (...) S1 else S2 when != E = E1 * E->f ... when any return ...; } else S3 // Signed-off-by: Julia Lawall Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c index 1387c5f..a47fd4e 100644 --- a/drivers/platform/x86/sony-laptop.c +++ b/drivers/platform/x86/sony-laptop.c @@ -1196,9 +1196,13 @@ static void sony_nc_rfkill_setup(struct acpi_device *device) } device_enum = (union acpi_object *) buffer.pointer; - if (!device_enum || device_enum->type != ACPI_TYPE_BUFFER) { - printk(KERN_ERR "Invalid SN06 return object 0x%.2x\n", - device_enum->type); + if (!device_enum) { + pr_err("Invalid SN06 return object\n"); + goto out_no_enum; + } + if (device_enum->type != ACPI_TYPE_BUFFER) { + pr_err("Invalid SN06 return object type 0x%.2x\n", + device_enum->type); goto out_no_enum; } -- cgit v0.10.2 From f35843ed8d17562f7c5da4b34a4a81b0cc450e9e Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Wed, 26 May 2010 12:00:10 -0300 Subject: classmate-laptop: depends on RFKILL or RFKILL=n Randy Dunlap has reported that building classmate-laptop fails when CONFIG_RFKILL=m and CONFIG_ACPI_CMPC=y. He suggested depending on RFKILL, but, then, it will not be possible to select classmate-laptop when RFKILL is off. There's no known problem with building and using classmate-laptop with RFKILL off. So depend on RFKILL or RFKILL=n. Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Matthew Garrett Reported-by: Randy Dunlap Cc: Randy Dunlap Cc: platform-driver-x86@vger.kernel.org Cc: Daniel Oliveira Nascimento diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 3e1b8a2..fe7d670 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -520,6 +520,7 @@ config TOSHIBA_BT_RFKILL config ACPI_CMPC tristate "CMPC Laptop Extras" depends on X86 && ACPI + depends on RFKILL || RFKILL=n select INPUT select BACKLIGHT_CLASS_DEVICE default n -- cgit v0.10.2 From 81f61484f16decba0fb68400fe0036b337b4cdc7 Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Sun, 23 May 2010 16:33:17 -0700 Subject: platform/x86: msi-laptop depends on SERIO_I8042 msi-laptop uses i8042_*() interfaces, so it should depend on SERIO_I8042. E.g., when SERIO_I8042=m and MSI_LAPTOP=y: msi-laptop.c:(.text+0x18a7fe): undefined reference to `i8042_install_filter' msi-laptop.c:(.init.text+0xd69d): undefined reference to `i8042_remove_filter' msi-laptop.c:(.exit.text+0x19c3): undefined reference to `i8042_remove_filter' Signed-off-by: Randy Dunlap Signed-off-by: Matthew Garrett Cc: Lennart Poettering diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index fe7d670..fd06001 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -151,6 +151,7 @@ config MSI_LAPTOP depends on ACPI depends on BACKLIGHT_CLASS_DEVICE depends on RFKILL + depends on SERIO_I8042 ---help--- This is a driver for laptops built by MSI (MICRO-STAR INTERNATIONAL): -- cgit v0.10.2 From 8cadd2831bf3abc94f4530e7fdbab7bb39b6b27d Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Mon, 10 May 2010 14:26:20 -0700 Subject: timer: add on-stack deferrable timer interfaces In some cases (for instance with kernel threads) it may be desireable to use on-stack deferrable timers to get their power saving benefits. Add interfaces to support this for the IPS driver. Signed-off-by: Jesse Barnes Signed-off-by: Matthew Garrett diff --git a/include/linux/timer.h b/include/linux/timer.h index ea965b8..38cf093 100644 --- a/include/linux/timer.h +++ b/include/linux/timer.h @@ -100,6 +100,13 @@ void init_timer_deferrable_key(struct timer_list *timer, setup_timer_on_stack_key((timer), #timer, &__key, \ (fn), (data)); \ } while (0) +#define setup_deferrable_timer_on_stack(timer, fn, data) \ + do { \ + static struct lock_class_key __key; \ + setup_deferrable_timer_on_stack_key((timer), #timer, \ + &__key, (fn), \ + (data)); \ + } while (0) #else #define init_timer(timer)\ init_timer_key((timer), NULL, NULL) @@ -111,6 +118,8 @@ void init_timer_deferrable_key(struct timer_list *timer, setup_timer_key((timer), NULL, NULL, (fn), (data)) #define setup_timer_on_stack(timer, fn, data)\ setup_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) +#define setup_deferrable_timer_on_stack(timer, fn, data)\ + setup_deferrable_timer_on_stack_key((timer), NULL, NULL, (fn), (data)) #endif #ifdef CONFIG_DEBUG_OBJECTS_TIMERS @@ -150,6 +159,12 @@ static inline void setup_timer_on_stack_key(struct timer_list *timer, init_timer_on_stack_key(timer, name, key); } +extern void setup_deferrable_timer_on_stack_key(struct timer_list *timer, + const char *name, + struct lock_class_key *key, + void (*function)(unsigned long), + unsigned long data); + /** * timer_pending - is a timer pending? * @timer: the timer in question diff --git a/kernel/timer.c b/kernel/timer.c index ee305c8..efde11e 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -577,6 +577,19 @@ static void __init_timer(struct timer_list *timer, lockdep_init_map(&timer->lockdep_map, name, key, 0); } +void setup_deferrable_timer_on_stack_key(struct timer_list *timer, + const char *name, + struct lock_class_key *key, + void (*function)(unsigned long), + unsigned long data) +{ + timer->function = function; + timer->data = data; + init_timer_on_stack_key(timer, name, key); + timer_set_deferrable(timer); +} +EXPORT_SYMBOL_GPL(setup_deferrable_timer_on_stack_key); + /** * init_timer_key - initialize a timer * @timer: the timer to be initialized -- cgit v0.10.2 From aa7ffc01d254c91a36bf854d57a14049c6134c72 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Fri, 14 May 2010 15:41:14 -0700 Subject: x86 platform driver: intelligent power sharing driver Intel Core i3/5 platforms with integrated graphics support both CPU and GPU turbo mode. CPU turbo mode is opportunistic: the CPU will use any available power to increase core frequencies if thermal headroom is available. The GPU side is more manual however; the graphics driver must monitor GPU power and temperature and coordinate with a core thermal driver to take advantage of available thermal and power headroom in the package. The intelligent power sharing (IPS) driver is intended to coordinate this activity by monitoring MCP (multi-chip package) temperature and power, allowing the CPU and/or GPU to increase their power consumption, and thus performance, when possible. The goal is to maximize performance within a given platform's TDP (thermal design point). Signed-off-by: Jesse Barnes Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index fd06001..724b2ed 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -539,4 +539,14 @@ config INTEL_SCU_IPC some embedded Intel x86 platforms. This is not needed for PC-type machines. +config INTEL_IPS + tristate "Intel Intelligent Power Sharing" + depends on ACPI + ---help--- + Intel Calpella platforms support dynamic power sharing between the + CPU and GPU, maximizing performance in a given TDP. This driver, + along with the CPU frequency and i915 drivers, provides that + functionality. If in doubt, say Y here; it will only load on + supported platforms. + endif # X86_PLATFORM_DEVICES diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 8770bfe..7318fc2 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -26,3 +26,4 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_TOSHIBA_BT_RFKILL) += toshiba_bluetooth.o obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o +obj-$(CONFIG_INTEL_IPS) += intel_ips.o diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c new file mode 100644 index 0000000..f1dce3b --- /dev/null +++ b/drivers/platform/x86/intel_ips.c @@ -0,0 +1,1655 @@ +/* + * Copyright (c) 2009-2010 Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + * The full GNU General Public License is included in this distribution in + * the file called "COPYING". + * + * Authors: + * Jesse Barnes + */ + +/* + * Some Intel Ibex Peak based platforms support so-called "intelligent + * power sharing", which allows the CPU and GPU to cooperate to maximize + * performance within a given TDP (thermal design point). This driver + * performs the coordination between the CPU and GPU, monitors thermal and + * power statistics in the platform, and initializes power monitoring + * hardware. It also provides a few tunables to control behavior. Its + * primary purpose is to safely allow CPU and GPU turbo modes to be enabled + * by tracking power and thermal budget; secondarily it can boost turbo + * performance by allocating more power or thermal budget to the CPU or GPU + * based on available headroom and activity. + * + * The basic algorithm is driven by a 5s moving average of tempurature. If + * thermal headroom is available, the CPU and/or GPU power clamps may be + * adjusted upwards. If we hit the thermal ceiling or a thermal trigger, + * we scale back the clamp. Aside from trigger events (when we're critically + * close or over our TDP) we don't adjust the clamps more than once every + * five seconds. + * + * The thermal device (device 31, function 6) has a set of registers that + * are updated by the ME firmware. The ME should also take the clamp values + * written to those registers and write them to the CPU, but we currently + * bypass that functionality and write the CPU MSR directly. + * + * UNSUPPORTED: + * - dual MCP configs + * + * TODO: + * - handle CPU hotplug + * - provide turbo enable/disable api + * - make sure we can write turbo enable/disable reg based on MISC_EN + * + * Related documents: + * - CDI 403777, 403778 - Auburndale EDS vol 1 & 2 + * - CDI 401376 - Ibex Peak EDS + * - ref 26037, 26641 - IPS BIOS spec + * - ref 26489 - Nehalem BIOS writer's guide + * - ref 26921 - Ibex Peak BIOS Specification + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PCI_DEVICE_ID_INTEL_THERMAL_SENSOR 0x3b32 + +/* + * Package level MSRs for monitor/control + */ +#define PLATFORM_INFO 0xce +#define PLATFORM_TDP (1<<29) +#define PLATFORM_RATIO (1<<28) + +#define IA32_MISC_ENABLE 0x1a0 +#define IA32_MISC_TURBO_EN (1ULL<<38) + +#define TURBO_POWER_CURRENT_LIMIT 0x1ac +#define TURBO_TDC_OVR_EN (1UL<<31) +#define TURBO_TDC_MASK (0x000000007fff0000UL) +#define TURBO_TDC_SHIFT (16) +#define TURBO_TDP_OVR_EN (1UL<<15) +#define TURBO_TDP_MASK (0x0000000000003fffUL) + +/* + * Core/thread MSRs for monitoring + */ +#define IA32_PERF_CTL 0x199 +#define IA32_PERF_TURBO_DIS (1ULL<<32) + +/* + * Thermal PCI device regs + */ +#define THM_CFG_TBAR 0x10 +#define THM_CFG_TBAR_HI 0x14 + +#define THM_TSIU 0x00 +#define THM_TSE 0x01 +#define TSE_EN 0xb8 +#define THM_TSS 0x02 +#define THM_TSTR 0x03 +#define THM_TSTTP 0x04 +#define THM_TSCO 0x08 +#define THM_TSES 0x0c +#define THM_TSGPEN 0x0d +#define TSGPEN_HOT_LOHI (1<<1) +#define TSGPEN_CRIT_LOHI (1<<2) +#define THM_TSPC 0x0e +#define THM_PPEC 0x10 +#define THM_CTA 0x12 +#define THM_PTA 0x14 +#define PTA_SLOPE_MASK (0xff00) +#define PTA_SLOPE_SHIFT 8 +#define PTA_OFFSET_MASK (0x00ff) +#define THM_MGTA 0x16 +#define MGTA_SLOPE_MASK (0xff00) +#define MGTA_SLOPE_SHIFT 8 +#define MGTA_OFFSET_MASK (0x00ff) +#define THM_TRC 0x1a +#define TRC_CORE2_EN (1<<15) +#define TRC_THM_EN (1<<12) +#define TRC_C6_WAR (1<<8) +#define TRC_CORE1_EN (1<<7) +#define TRC_CORE_PWR (1<<6) +#define TRC_PCH_EN (1<<5) +#define TRC_MCH_EN (1<<4) +#define TRC_DIMM4 (1<<3) +#define TRC_DIMM3 (1<<2) +#define TRC_DIMM2 (1<<1) +#define TRC_DIMM1 (1<<0) +#define THM_TES 0x20 +#define THM_TEN 0x21 +#define TEN_UPDATE_EN 1 +#define THM_PSC 0x24 +#define PSC_NTG (1<<0) /* No GFX turbo support */ +#define PSC_NTPC (1<<1) /* No CPU turbo support */ +#define PSC_PP_DEF (0<<2) /* Perf policy up to driver */ +#define PSP_PP_PC (1<<2) /* BIOS prefers CPU perf */ +#define PSP_PP_BAL (2<<2) /* BIOS wants balanced perf */ +#define PSP_PP_GFX (3<<2) /* BIOS prefers GFX perf */ +#define PSP_PBRT (1<<4) /* BIOS run time support */ +#define THM_CTV1 0x30 +#define CTV_TEMP_ERROR (1<<15) +#define CTV_TEMP_MASK 0x3f +#define CTV_ +#define THM_CTV2 0x32 +#define THM_CEC 0x34 /* undocumented power accumulator in joules */ +#define THM_AE 0x3f +#define THM_HTS 0x50 /* 32 bits */ +#define HTS_PCPL_MASK (0x7fe00000) +#define HTS_PCPL_SHIFT 21 +#define HTS_GPL_MASK (0x001ff000) +#define HTS_GPL_SHIFT 12 +#define HTS_PP_MASK (0x00000c00) +#define HTS_PP_SHIFT 10 +#define HTS_PP_DEF 0 +#define HTS_PP_PROC 1 +#define HTS_PP_BAL 2 +#define HTS_PP_GFX 3 +#define HTS_PCTD_DIS (1<<9) +#define HTS_GTD_DIS (1<<8) +#define HTS_PTL_MASK (0x000000fe) +#define HTS_PTL_SHIFT 1 +#define HTS_NVV (1<<0) +#define THM_HTSHI 0x54 /* 16 bits */ +#define HTS2_PPL_MASK (0x03ff) +#define HTS2_PRST_MASK (0x3c00) +#define HTS2_PRST_SHIFT 10 +#define HTS2_PRST_UNLOADED 0 +#define HTS2_PRST_RUNNING 1 +#define HTS2_PRST_TDISOP 2 /* turbo disabled due to power */ +#define HTS2_PRST_TDISHT 3 /* turbo disabled due to high temp */ +#define HTS2_PRST_TDISUSR 4 /* user disabled turbo */ +#define HTS2_PRST_TDISPLAT 5 /* platform disabled turbo */ +#define HTS2_PRST_TDISPM 6 /* power management disabled turbo */ +#define HTS2_PRST_TDISERR 7 /* some kind of error disabled turbo */ +#define THM_PTL 0x56 +#define THM_MGTV 0x58 +#define TV_MASK 0x000000000000ff00 +#define TV_SHIFT 8 +#define THM_PTV 0x60 +#define PTV_MASK 0x00ff +#define THM_MMGPC 0x64 +#define THM_MPPC 0x66 +#define THM_MPCPC 0x68 +#define THM_TSPIEN 0x82 +#define TSPIEN_AUX_LOHI (1<<0) +#define TSPIEN_HOT_LOHI (1<<1) +#define TSPIEN_CRIT_LOHI (1<<2) +#define TSPIEN_AUX2_LOHI (1<<3) +#define THM_TSLOCK 0x83 +#define THM_ATR 0x84 +#define THM_TOF 0x87 +#define THM_STS 0x98 +#define STS_PCPL_MASK (0x7fe00000) +#define STS_PCPL_SHIFT 21 +#define STS_GPL_MASK (0x001ff000) +#define STS_GPL_SHIFT 12 +#define STS_PP_MASK (0x00000c00) +#define STS_PP_SHIFT 10 +#define STS_PP_DEF 0 +#define STS_PP_PROC 1 +#define STS_PP_BAL 2 +#define STS_PP_GFX 3 +#define STS_PCTD_DIS (1<<9) +#define STS_GTD_DIS (1<<8) +#define STS_PTL_MASK (0x000000fe) +#define STS_PTL_SHIFT 1 +#define STS_NVV (1<<0) +#define THM_SEC 0x9c +#define SEC_ACK (1<<0) +#define THM_TC3 0xa4 +#define THM_TC1 0xa8 +#define STS_PPL_MASK (0x0003ff00) +#define STS_PPL_SHIFT 16 +#define THM_TC2 0xac +#define THM_DTV 0xb0 +#define THM_ITV 0xd8 +#define ITV_ME_SEQNO_MASK 0x000f0000 /* ME should update every ~200ms */ +#define ITV_ME_SEQNO_SHIFT (16) +#define ITV_MCH_TEMP_MASK 0x0000ff00 +#define ITV_MCH_TEMP_SHIFT (8) +#define ITV_PCH_TEMP_MASK 0x000000ff + +#define thm_readb(off) readb(ips->regmap + (off)) +#define thm_readw(off) readw(ips->regmap + (off)) +#define thm_readl(off) readl(ips->regmap + (off)) +#define thm_readq(off) readq(ips->regmap + (off)) + +#define thm_writeb(off, val) writeb((val), ips->regmap + (off)) +#define thm_writew(off, val) writew((val), ips->regmap + (off)) +#define thm_writel(off, val) writel((val), ips->regmap + (off)) + +static const int IPS_ADJUST_PERIOD = 5000; /* ms */ + +/* For initial average collection */ +static const int IPS_SAMPLE_PERIOD = 200; /* ms */ +static const int IPS_SAMPLE_WINDOW = 5000; /* 5s moving window of samples */ +#define IPS_SAMPLE_COUNT (IPS_SAMPLE_WINDOW / IPS_SAMPLE_PERIOD) + +/* Per-SKU limits */ +struct ips_mcp_limits { + int cpu_family; + int cpu_model; /* includes extended model... */ + int mcp_power_limit; /* mW units */ + int core_power_limit; + int mch_power_limit; + int core_temp_limit; /* degrees C */ + int mch_temp_limit; +}; + +/* Max temps are -10 degrees C to avoid PROCHOT# */ + +struct ips_mcp_limits ips_sv_limits = { + .mcp_power_limit = 35000, + .core_power_limit = 29000, + .mch_power_limit = 20000, + .core_temp_limit = 95, + .mch_temp_limit = 90 +}; + +struct ips_mcp_limits ips_lv_limits = { + .mcp_power_limit = 25000, + .core_power_limit = 21000, + .mch_power_limit = 13000, + .core_temp_limit = 95, + .mch_temp_limit = 90 +}; + +struct ips_mcp_limits ips_ulv_limits = { + .mcp_power_limit = 18000, + .core_power_limit = 14000, + .mch_power_limit = 11000, + .core_temp_limit = 95, + .mch_temp_limit = 90 +}; + +struct ips_driver { + struct pci_dev *dev; + void *regmap; + struct task_struct *monitor; + struct task_struct *adjust; + struct dentry *debug_root; + + /* Average CPU core temps (all averages in .01 degrees C for precision) */ + u16 ctv1_avg_temp; + u16 ctv2_avg_temp; + /* GMCH average */ + u16 mch_avg_temp; + /* Average for the CPU (both cores?) */ + u16 mcp_avg_temp; + /* Average power consumption (in mW) */ + u32 cpu_avg_power; + u32 mch_avg_power; + + /* Offset values */ + u16 cta_val; + u16 pta_val; + u16 mgta_val; + + /* Maximums & prefs, protected by turbo status lock */ + spinlock_t turbo_status_lock; + u16 mcp_temp_limit; + u16 mcp_power_limit; + u16 core_power_limit; + u16 mch_power_limit; + bool cpu_turbo_enabled; + bool __cpu_turbo_on; + bool gpu_turbo_enabled; + bool __gpu_turbo_on; + bool gpu_preferred; + bool poll_turbo_status; + bool second_cpu; + struct ips_mcp_limits *limits; + + /* Optional MCH interfaces for if i915 is in use */ + unsigned long (*read_mch_val)(void); + bool (*gpu_raise)(void); + bool (*gpu_lower)(void); + bool (*gpu_busy)(void); + bool (*gpu_turbo_disable)(void); + + /* For restoration at unload */ + u64 orig_turbo_limit; + u64 orig_turbo_ratios; +}; + +/** + * ips_cpu_busy - is CPU busy? + * @ips: IPS driver struct + * + * Check CPU for load to see whether we should increase its thermal budget. + * + * RETURNS: + * True if the CPU could use more power, false otherwise. + */ +static bool ips_cpu_busy(struct ips_driver *ips) +{ + if ((avenrun[0] >> FSHIFT) > 1) + return true; + + return false; +} + +/** + * ips_cpu_raise - raise CPU power clamp + * @ips: IPS driver struct + * + * Raise the CPU power clamp by %IPS_CPU_STEP, in accordance with TDP for + * this platform. + * + * We do this by adjusting the TURBO_POWER_CURRENT_LIMIT MSR upwards (as + * long as we haven't hit the TDP limit for the SKU). + */ +static void ips_cpu_raise(struct ips_driver *ips) +{ + u64 turbo_override; + u16 cur_tdp_limit, new_tdp_limit; + + if (!ips->cpu_turbo_enabled) + return; + + rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); + + cur_tdp_limit = turbo_override & TURBO_TDP_MASK; + new_tdp_limit = cur_tdp_limit + 8; /* 1W increase */ + + /* Clamp to SKU TDP limit */ + if (((new_tdp_limit * 10) / 8) > ips->core_power_limit) + new_tdp_limit = cur_tdp_limit; + + thm_writew(THM_MPCPC, (new_tdp_limit * 10) / 8); + + turbo_override |= TURBO_TDC_OVR_EN | TURBO_TDC_OVR_EN; + wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); + + turbo_override &= ~TURBO_TDP_MASK; + turbo_override |= new_tdp_limit; + + wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); +} + +/** + * ips_cpu_lower - lower CPU power clamp + * @ips: IPS driver struct + * + * Lower CPU power clamp b %IPS_CPU_STEP if possible. + * + * We do this by adjusting the TURBO_POWER_CURRENT_LIMIT MSR down, going + * as low as the platform limits will allow (though we could go lower there + * wouldn't be much point). + */ +static void ips_cpu_lower(struct ips_driver *ips) +{ + u64 turbo_override; + u16 cur_limit, new_limit; + + rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); + + cur_limit = turbo_override & TURBO_TDP_MASK; + new_limit = cur_limit - 8; /* 1W decrease */ + + /* Clamp to SKU TDP limit */ + if (((new_limit * 10) / 8) < (ips->orig_turbo_limit & TURBO_TDP_MASK)) + new_limit = ips->orig_turbo_limit & TURBO_TDP_MASK; + + thm_writew(THM_MPCPC, (new_limit * 10) / 8); + + turbo_override |= TURBO_TDC_OVR_EN | TURBO_TDC_OVR_EN; + wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); + + turbo_override &= ~TURBO_TDP_MASK; + turbo_override |= new_limit; + + wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); +} + +/** + * do_enable_cpu_turbo - internal turbo enable function + * @data: unused + * + * Internal function for actually updating MSRs. When we enable/disable + * turbo, we need to do it on each CPU; this function is the one called + * by on_each_cpu() when needed. + */ +static void do_enable_cpu_turbo(void *data) +{ + u64 perf_ctl; + + rdmsrl(IA32_PERF_CTL, perf_ctl); + if (perf_ctl & IA32_PERF_TURBO_DIS) { + perf_ctl &= ~IA32_PERF_TURBO_DIS; + wrmsrl(IA32_PERF_CTL, perf_ctl); + } +} + +/** + * ips_enable_cpu_turbo - enable turbo mode on all CPUs + * @ips: IPS driver struct + * + * Enable turbo mode by clearing the disable bit in IA32_PERF_CTL on + * all logical threads. + */ +static void ips_enable_cpu_turbo(struct ips_driver *ips) +{ + /* Already on, no need to mess with MSRs */ + if (ips->__cpu_turbo_on) + return; + + on_each_cpu(do_enable_cpu_turbo, ips, 1); + + ips->__cpu_turbo_on = true; +} + +/** + * do_disable_cpu_turbo - internal turbo disable function + * @data: unused + * + * Internal function for actually updating MSRs. When we enable/disable + * turbo, we need to do it on each CPU; this function is the one called + * by on_each_cpu() when needed. + */ +static void do_disable_cpu_turbo(void *data) +{ + u64 perf_ctl; + + rdmsrl(IA32_PERF_CTL, perf_ctl); + if (!(perf_ctl & IA32_PERF_TURBO_DIS)) { + perf_ctl |= IA32_PERF_TURBO_DIS; + wrmsrl(IA32_PERF_CTL, perf_ctl); + } +} + +/** + * ips_disable_cpu_turbo - disable turbo mode on all CPUs + * @ips: IPS driver struct + * + * Disable turbo mode by setting the disable bit in IA32_PERF_CTL on + * all logical threads. + */ +static void ips_disable_cpu_turbo(struct ips_driver *ips) +{ + /* Already off, leave it */ + if (!ips->__cpu_turbo_on) + return; + + on_each_cpu(do_disable_cpu_turbo, ips, 1); + + ips->__cpu_turbo_on = false; +} + +/** + * ips_gpu_busy - is GPU busy? + * @ips: IPS driver struct + * + * Check GPU for load to see whether we should increase its thermal budget. + * We need to call into the i915 driver in this case. + * + * RETURNS: + * True if the GPU could use more power, false otherwise. + */ +static bool ips_gpu_busy(struct ips_driver *ips) +{ + return false; +} + +/** + * ips_gpu_raise - raise GPU power clamp + * @ips: IPS driver struct + * + * Raise the GPU frequency/power if possible. We need to call into the + * i915 driver in this case. + */ +static void ips_gpu_raise(struct ips_driver *ips) +{ + if (!ips->gpu_turbo_enabled) + return; + + if (!ips->gpu_raise()) + ips->gpu_turbo_enabled = false; + + return; +} + +/** + * ips_gpu_lower - lower GPU power clamp + * @ips: IPS driver struct + * + * Lower GPU frequency/power if possible. Need to call i915. + */ +static void ips_gpu_lower(struct ips_driver *ips) +{ + if (!ips->gpu_turbo_enabled) + return; + + if (!ips->gpu_lower()) + ips->gpu_turbo_enabled = false; + + return; +} + +/** + * ips_enable_gpu_turbo - notify the gfx driver turbo is available + * @ips: IPS driver struct + * + * Call into the graphics driver indicating that it can safely use + * turbo mode. + */ +static void ips_enable_gpu_turbo(struct ips_driver *ips) +{ + if (ips->__gpu_turbo_on) + return; + ips->__gpu_turbo_on = true; +} + +/** + * ips_disable_gpu_turbo - notify the gfx driver to disable turbo mode + * @ips: IPS driver struct + * + * Request that the graphics driver disable turbo mode. + */ +static void ips_disable_gpu_turbo(struct ips_driver *ips) +{ + /* Avoid calling i915 if turbo is already disabled */ + if (!ips->__gpu_turbo_on) + return; + + if (!ips->gpu_turbo_disable()) + dev_err(&ips->dev->dev, "failed to disable graphis turbo\n"); + else + ips->__gpu_turbo_on = false; +} + +/** + * mcp_exceeded - check whether we're outside our thermal & power limits + * @ips: IPS driver struct + * + * Check whether the MCP is over its thermal or power budget. + */ +static bool mcp_exceeded(struct ips_driver *ips) +{ + unsigned long flags; + bool ret = false; + + spin_lock_irqsave(&ips->turbo_status_lock, flags); + if (ips->mcp_avg_temp > (ips->mcp_temp_limit * 100)) + ret = true; + if (ips->cpu_avg_power + ips->mch_avg_power > ips->mcp_power_limit) + ret = true; + spin_unlock_irqrestore(&ips->turbo_status_lock, flags); + + if (ret) + dev_warn(&ips->dev->dev, + "MCP power or thermal limit exceeded\n"); + + return ret; +} + +/** + * cpu_exceeded - check whether a CPU core is outside its limits + * @ips: IPS driver struct + * @cpu: CPU number to check + * + * Check a given CPU's average temp or power is over its limit. + */ +static bool cpu_exceeded(struct ips_driver *ips, int cpu) +{ + unsigned long flags; + int avg; + bool ret = false; + + spin_lock_irqsave(&ips->turbo_status_lock, flags); + avg = cpu ? ips->ctv2_avg_temp : ips->ctv1_avg_temp; + if (avg > (ips->limits->core_temp_limit * 100)) + ret = true; + if (ips->cpu_avg_power > ips->core_power_limit) + ret = true; + spin_unlock_irqrestore(&ips->turbo_status_lock, flags); + + if (ret) + dev_warn(&ips->dev->dev, + "CPU power or thermal limit exceeded\n"); + + return ret; +} + +/** + * mch_exceeded - check whether the GPU is over budget + * @ips: IPS driver struct + * + * Check the MCH temp & power against their maximums. + */ +static bool mch_exceeded(struct ips_driver *ips) +{ + unsigned long flags; + bool ret = false; + + spin_lock_irqsave(&ips->turbo_status_lock, flags); + if (ips->mch_avg_temp > (ips->limits->mch_temp_limit * 100)) + ret = true; + spin_unlock_irqrestore(&ips->turbo_status_lock, flags); + + return ret; +} + +/** + * update_turbo_limits - get various limits & settings from regs + * @ips: IPS driver struct + * + * Update the IPS power & temp limits, along with turbo enable flags, + * based on latest register contents. + * + * Used at init time and for runtime BIOS support, which requires polling + * the regs for updates (as a result of AC->DC transition for example). + * + * LOCKING: + * Caller must hold turbo_status_lock (outside of init) + */ +static void update_turbo_limits(struct ips_driver *ips) +{ + u32 hts = thm_readl(THM_HTS); + + ips->cpu_turbo_enabled = !(hts & HTS_PCTD_DIS); + ips->gpu_turbo_enabled = !(hts & HTS_GTD_DIS); + ips->core_power_limit = thm_readw(THM_MPCPC); + ips->mch_power_limit = thm_readw(THM_MMGPC); + ips->mcp_temp_limit = thm_readw(THM_PTL); + ips->mcp_power_limit = thm_readw(THM_MPPC); + + /* Ignore BIOS CPU vs GPU pref */ +} + +/** + * ips_adjust - adjust power clamp based on thermal state + * @data: ips driver structure + * + * Wake up every 5s or so and check whether we should adjust the power clamp. + * Check CPU and GPU load to determine which needs adjustment. There are + * several things to consider here: + * - do we need to adjust up or down? + * - is CPU busy? + * - is GPU busy? + * - is CPU in turbo? + * - is GPU in turbo? + * - is CPU or GPU preferred? (CPU is default) + * + * So, given the above, we do the following: + * - up (TDP available) + * - CPU not busy, GPU not busy - nothing + * - CPU busy, GPU not busy - adjust CPU up + * - CPU not busy, GPU busy - adjust GPU up + * - CPU busy, GPU busy - adjust preferred unit up, taking headroom from + * non-preferred unit if necessary + * - down (at TDP limit) + * - adjust both CPU and GPU down if possible + * + cpu+ gpu+ cpu+gpu- cpu-gpu+ cpu-gpu- +cpu < gpu < cpu+gpu+ cpu+ gpu+ nothing +cpu < gpu >= cpu+gpu-(mcp<) cpu+gpu-(mcp<) gpu- gpu- +cpu >= gpu < cpu-gpu+(mcp<) cpu- cpu-gpu+(mcp<) cpu- +cpu >= gpu >= cpu-gpu- cpu-gpu- cpu-gpu- cpu-gpu- + * + */ +static int ips_adjust(void *data) +{ + struct ips_driver *ips = data; + unsigned long flags; + + dev_dbg(&ips->dev->dev, "starting ips-adjust thread\n"); + + /* + * Adjust CPU and GPU clamps every 5s if needed. Doing it more + * often isn't recommended due to ME interaction. + */ + do { + bool cpu_busy = ips_cpu_busy(ips); + bool gpu_busy = ips_gpu_busy(ips); + + spin_lock_irqsave(&ips->turbo_status_lock, flags); + if (ips->poll_turbo_status) + update_turbo_limits(ips); + spin_unlock_irqrestore(&ips->turbo_status_lock, flags); + + /* Update turbo status if necessary */ + if (ips->cpu_turbo_enabled) + ips_enable_cpu_turbo(ips); + else + ips_disable_cpu_turbo(ips); + + if (ips->gpu_turbo_enabled) + ips_enable_gpu_turbo(ips); + else + ips_disable_gpu_turbo(ips); + + /* We're outside our comfort zone, crank them down */ + if (!mcp_exceeded(ips)) { + ips_cpu_lower(ips); + ips_gpu_lower(ips); + goto sleep; + } + + if (!cpu_exceeded(ips, 0) && cpu_busy) + ips_cpu_raise(ips); + else + ips_cpu_lower(ips); + + if (!mch_exceeded(ips) && gpu_busy) + ips_gpu_raise(ips); + else + ips_gpu_lower(ips); + +sleep: + schedule_timeout_interruptible(msecs_to_jiffies(IPS_ADJUST_PERIOD)); + } while (!kthread_should_stop()); + + dev_dbg(&ips->dev->dev, "ips-adjust thread stopped\n"); + + return 0; +} + +/* + * Helpers for reading out temp/power values and calculating their + * averages for the decision making and monitoring functions. + */ + +static u16 calc_avg_temp(struct ips_driver *ips, u16 *array) +{ + u64 total = 0; + int i; + u16 avg; + + for (i = 0; i < IPS_SAMPLE_COUNT; i++) + total += (u64)(array[i] * 100); + + do_div(total, IPS_SAMPLE_COUNT); + + avg = (u16)total; + + return avg; +} + +static u16 read_mgtv(struct ips_driver *ips) +{ + u16 ret; + u64 slope, offset; + u64 val; + + val = thm_readq(THM_MGTV); + val = (val & TV_MASK) >> TV_SHIFT; + + slope = offset = thm_readw(THM_MGTA); + slope = (slope & MGTA_SLOPE_MASK) >> MGTA_SLOPE_SHIFT; + offset = offset & MGTA_OFFSET_MASK; + + ret = ((val * slope + 0x40) >> 7) + offset; + + + return ret; +} + +static u16 read_ptv(struct ips_driver *ips) +{ + u16 val, slope, offset; + + slope = (ips->pta_val & PTA_SLOPE_MASK) >> PTA_SLOPE_SHIFT; + offset = ips->pta_val & PTA_OFFSET_MASK; + + val = thm_readw(THM_PTV) & PTV_MASK; + + return val; +} + +static u16 read_ctv(struct ips_driver *ips, int cpu) +{ + int reg = cpu ? THM_CTV2 : THM_CTV1; + u16 val; + + val = thm_readw(reg); + if (!(val & CTV_TEMP_ERROR)) + val = (val) >> 6; /* discard fractional component */ + else + val = 0; + + return val; +} + +static u32 get_cpu_power(struct ips_driver *ips, u32 *last, int period) +{ + u32 val; + u32 ret; + + /* + * CEC is in joules/65535. Take difference over time to + * get watts. + */ + val = thm_readl(THM_CEC); + + /* period is in ms and we want mW */ + ret = (((val - *last) * 1000) / period); + ret = (ret * 1000) / 65535; + *last = val; + + return ret; +} + +static const u16 temp_decay_factor = 2; +static u16 update_average_temp(u16 avg, u16 val) +{ + u16 ret; + + /* Multiply by 100 for extra precision */ + ret = (val * 100 / temp_decay_factor) + + (((temp_decay_factor - 1) * avg) / temp_decay_factor); + return ret; +} + +static const u16 power_decay_factor = 2; +static u16 update_average_power(u32 avg, u32 val) +{ + u32 ret; + + ret = (val / power_decay_factor) + + (((power_decay_factor - 1) * avg) / power_decay_factor); + + return ret; +} + +static u32 calc_avg_power(struct ips_driver *ips, u32 *array) +{ + u64 total = 0; + u32 avg; + int i; + + for (i = 0; i < IPS_SAMPLE_COUNT; i++) + total += array[i]; + + do_div(total, IPS_SAMPLE_COUNT); + avg = (u32)total; + + return avg; +} + +static void monitor_timeout(unsigned long arg) +{ + wake_up_process((struct task_struct *)arg); +} + +/** + * ips_monitor - temp/power monitoring thread + * @data: ips driver structure + * + * This is the main function for the IPS driver. It monitors power and + * tempurature in the MCP and adjusts CPU and GPU power clams accordingly. + * + * We keep a 5s moving average of power consumption and tempurature. Using + * that data, along with CPU vs GPU preference, we adjust the power clamps + * up or down. + */ +static int ips_monitor(void *data) +{ + struct ips_driver *ips = data; + struct timer_list timer; + unsigned long seqno_timestamp, expire, last_msecs, last_sample_period; + int i; + u32 *cpu_samples = NULL, *mchp_samples = NULL, old_cpu_power; + u16 *mcp_samples = NULL, *ctv1_samples = NULL, *ctv2_samples = NULL, + *mch_samples = NULL; + u8 cur_seqno, last_seqno; + + mcp_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); + ctv1_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); + ctv2_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); + mch_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); + cpu_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL); + mchp_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL); + if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples) { + dev_err(&ips->dev->dev, + "failed to allocate sample array, ips disabled\n"); + kfree(mcp_samples); + kfree(ctv1_samples); + kfree(ctv2_samples); + kfree(mch_samples); + kfree(cpu_samples); + kthread_stop(ips->adjust); + return -ENOMEM; + } + + last_seqno = (thm_readl(THM_ITV) & ITV_ME_SEQNO_MASK) >> + ITV_ME_SEQNO_SHIFT; + seqno_timestamp = get_jiffies_64(); + + old_cpu_power = thm_readl(THM_CEC) / 65535; + schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD)); + + /* Collect an initial average */ + for (i = 0; i < IPS_SAMPLE_COUNT; i++) { + u32 mchp, cpu_power; + u16 val; + + mcp_samples[i] = read_ptv(ips); + + val = read_ctv(ips, 0); + ctv1_samples[i] = val; + + val = read_ctv(ips, 1); + ctv2_samples[i] = val; + + val = read_mgtv(ips); + mch_samples[i] = val; + + cpu_power = get_cpu_power(ips, &old_cpu_power, + IPS_SAMPLE_PERIOD); + cpu_samples[i] = cpu_power; + + if (ips->read_mch_val) { + mchp = ips->read_mch_val(); + mchp_samples[i] = mchp; + } + + schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD)); + if (kthread_should_stop()) + break; + } + + ips->mcp_avg_temp = calc_avg_temp(ips, mcp_samples); + ips->ctv1_avg_temp = calc_avg_temp(ips, ctv1_samples); + ips->ctv2_avg_temp = calc_avg_temp(ips, ctv2_samples); + ips->mch_avg_temp = calc_avg_temp(ips, mch_samples); + ips->cpu_avg_power = calc_avg_power(ips, cpu_samples); + ips->mch_avg_power = calc_avg_power(ips, mchp_samples); + kfree(mcp_samples); + kfree(ctv1_samples); + kfree(ctv2_samples); + kfree(mch_samples); + kfree(cpu_samples); + kfree(mchp_samples); + + /* Start the adjustment thread now that we have data */ + wake_up_process(ips->adjust); + + /* + * Ok, now we have an initial avg. From here on out, we track the + * running avg using a decaying average calculation. This allows + * us to reduce the sample frequency if the CPU and GPU are idle. + */ + old_cpu_power = thm_readl(THM_CEC); + schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD)); + last_sample_period = IPS_SAMPLE_PERIOD; + + setup_deferrable_timer_on_stack(&timer, monitor_timeout, + (unsigned long)current); + do { + u32 cpu_val, mch_val; + u16 val; + + /* MCP itself */ + val = read_ptv(ips); + ips->mcp_avg_temp = update_average_temp(ips->mcp_avg_temp, val); + + /* Processor 0 */ + val = read_ctv(ips, 0); + ips->ctv1_avg_temp = + update_average_temp(ips->ctv1_avg_temp, val); + /* Power */ + cpu_val = get_cpu_power(ips, &old_cpu_power, + last_sample_period); + ips->cpu_avg_power = + update_average_power(ips->cpu_avg_power, cpu_val); + + if (ips->second_cpu) { + /* Processor 1 */ + val = read_ctv(ips, 1); + ips->ctv2_avg_temp = + update_average_temp(ips->ctv2_avg_temp, val); + } + + /* MCH */ + val = read_mgtv(ips); + ips->mch_avg_temp = update_average_temp(ips->mch_avg_temp, val); + /* Power */ + if (ips->read_mch_val) { + mch_val = ips->read_mch_val(); + ips->mch_avg_power = + update_average_power(ips->mch_avg_power, + mch_val); + } + + /* + * Make sure ME is updating thermal regs. + * Note: + * If it's been more than a second since the last update, + * the ME is probably hung. + */ + cur_seqno = (thm_readl(THM_ITV) & ITV_ME_SEQNO_MASK) >> + ITV_ME_SEQNO_SHIFT; + if (cur_seqno == last_seqno && + time_after(jiffies, seqno_timestamp + HZ)) { + dev_warn(&ips->dev->dev, "ME failed to update for more than 1s, likely hung\n"); + } else { + seqno_timestamp = get_jiffies_64(); + last_seqno = cur_seqno; + } + + last_msecs = jiffies_to_msecs(jiffies); + expire = jiffies + msecs_to_jiffies(IPS_SAMPLE_PERIOD); + + __set_current_state(TASK_UNINTERRUPTIBLE); + mod_timer(&timer, expire); + schedule(); + + /* Calculate actual sample period for power averaging */ + last_sample_period = jiffies_to_msecs(jiffies) - last_msecs; + if (!last_sample_period) + last_sample_period = 1; + } while (!kthread_should_stop()); + + del_timer_sync(&timer); + destroy_timer_on_stack(&timer); + + dev_dbg(&ips->dev->dev, "ips-monitor thread stopped\n"); + + return 0; +} + +#if 0 +#define THM_DUMPW(reg) \ + { \ + u16 val = thm_readw(reg); \ + dev_dbg(&ips->dev->dev, #reg ": 0x%04x\n", val); \ + } +#define THM_DUMPL(reg) \ + { \ + u32 val = thm_readl(reg); \ + dev_dbg(&ips->dev->dev, #reg ": 0x%08x\n", val); \ + } +#define THM_DUMPQ(reg) \ + { \ + u64 val = thm_readq(reg); \ + dev_dbg(&ips->dev->dev, #reg ": 0x%016x\n", val); \ + } + +static void dump_thermal_info(struct ips_driver *ips) +{ + u16 ptl; + + ptl = thm_readw(THM_PTL); + dev_dbg(&ips->dev->dev, "Processor temp limit: %d\n", ptl); + + THM_DUMPW(THM_CTA); + THM_DUMPW(THM_TRC); + THM_DUMPW(THM_CTV1); + THM_DUMPL(THM_STS); + THM_DUMPW(THM_PTV); + THM_DUMPQ(THM_MGTV); +} +#endif + +/** + * ips_irq_handler - handle temperature triggers and other IPS events + * @irq: irq number + * @arg: unused + * + * Handle temperature limit trigger events, generally by lowering the clamps. + * If we're at a critical limit, we clamp back to the lowest possible value + * to prevent emergency shutdown. + */ +static irqreturn_t ips_irq_handler(int irq, void *arg) +{ + struct ips_driver *ips = arg; + u8 tses = thm_readb(THM_TSES); + u8 tes = thm_readb(THM_TES); + + if (!tses && !tes) + return IRQ_NONE; + + dev_info(&ips->dev->dev, "TSES: 0x%02x\n", tses); + dev_info(&ips->dev->dev, "TES: 0x%02x\n", tes); + + /* STS update from EC? */ + if (tes & 1) { + u32 sts, tc1; + + sts = thm_readl(THM_STS); + tc1 = thm_readl(THM_TC1); + + if (sts & STS_NVV) { + spin_lock(&ips->turbo_status_lock); + ips->core_power_limit = (sts & STS_PCPL_MASK) >> + STS_PCPL_SHIFT; + ips->mch_power_limit = (sts & STS_GPL_MASK) >> + STS_GPL_SHIFT; + /* ignore EC CPU vs GPU pref */ + ips->cpu_turbo_enabled = !(sts & STS_PCTD_DIS); + ips->gpu_turbo_enabled = !(sts & STS_GTD_DIS); + ips->mcp_temp_limit = (sts & STS_PTL_MASK) >> + STS_PTL_SHIFT; + ips->mcp_power_limit = (tc1 & STS_PPL_MASK) >> + STS_PPL_SHIFT; + spin_unlock(&ips->turbo_status_lock); + + thm_writeb(THM_SEC, SEC_ACK); + } + thm_writeb(THM_TES, tes); + } + + /* Thermal trip */ + if (tses) { + dev_warn(&ips->dev->dev, + "thermal trip occurred, tses: 0x%04x\n", tses); + thm_writeb(THM_TSES, tses); + } + + return IRQ_HANDLED; +} + +#ifndef CONFIG_DEBUG_FS +static void ips_debugfs_init(struct ips_driver *ips) { return; } +static void ips_debugfs_cleanup(struct ips_driver *ips) { return; } +#else + +/* Expose current state and limits in debugfs if possible */ + +struct ips_debugfs_node { + struct ips_driver *ips; + char *name; + int (*show)(struct seq_file *m, void *data); +}; + +static int show_cpu_temp(struct seq_file *m, void *data) +{ + struct ips_driver *ips = m->private; + + seq_printf(m, "%d.%02d\n", ips->ctv1_avg_temp / 100, + ips->ctv1_avg_temp % 100); + + return 0; +} + +static int show_cpu_power(struct seq_file *m, void *data) +{ + struct ips_driver *ips = m->private; + + seq_printf(m, "%dmW\n", ips->cpu_avg_power); + + return 0; +} + +static int show_cpu_clamp(struct seq_file *m, void *data) +{ + u64 turbo_override; + int tdp, tdc; + + rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); + + tdp = (int)(turbo_override & TURBO_TDP_MASK); + tdc = (int)((turbo_override & TURBO_TDC_MASK) >> TURBO_TDC_SHIFT); + + /* Convert to .1W/A units */ + tdp = tdp * 10 / 8; + tdc = tdc * 10 / 8; + + /* Watts Amperes */ + seq_printf(m, "%d.%dW %d.%dA\n", tdp / 10, tdp % 10, + tdc / 10, tdc % 10); + + return 0; +} + +static int show_mch_temp(struct seq_file *m, void *data) +{ + struct ips_driver *ips = m->private; + + seq_printf(m, "%d.%02d\n", ips->mch_avg_temp / 100, + ips->mch_avg_temp % 100); + + return 0; +} + +static int show_mch_power(struct seq_file *m, void *data) +{ + struct ips_driver *ips = m->private; + + seq_printf(m, "%dmW\n", ips->mch_avg_power); + + return 0; +} + +static struct ips_debugfs_node ips_debug_files[] = { + { NULL, "cpu_temp", show_cpu_temp }, + { NULL, "cpu_power", show_cpu_power }, + { NULL, "cpu_clamp", show_cpu_clamp }, + { NULL, "mch_temp", show_mch_temp }, + { NULL, "mch_power", show_mch_power }, +}; + +static int ips_debugfs_open(struct inode *inode, struct file *file) +{ + struct ips_debugfs_node *node = inode->i_private; + + return single_open(file, node->show, node->ips); +} + +static const struct file_operations ips_debugfs_ops = { + .owner = THIS_MODULE, + .open = ips_debugfs_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static void ips_debugfs_cleanup(struct ips_driver *ips) +{ + if (ips->debug_root) + debugfs_remove_recursive(ips->debug_root); + return; +} + +static void ips_debugfs_init(struct ips_driver *ips) +{ + int i; + + ips->debug_root = debugfs_create_dir("ips", NULL); + if (!ips->debug_root) { + dev_err(&ips->dev->dev, + "failed to create debugfs entries: %ld\n", + PTR_ERR(ips->debug_root)); + return; + } + + for (i = 0; i < ARRAY_SIZE(ips_debug_files); i++) { + struct dentry *ent; + struct ips_debugfs_node *node = &ips_debug_files[i]; + + node->ips = ips; + ent = debugfs_create_file(node->name, S_IFREG | S_IRUGO, + ips->debug_root, node, + &ips_debugfs_ops); + if (!ent) { + dev_err(&ips->dev->dev, + "failed to create debug file: %ld\n", + PTR_ERR(ent)); + goto err_cleanup; + } + } + + return; + +err_cleanup: + ips_debugfs_cleanup(ips); + return; +} +#endif /* CONFIG_DEBUG_FS */ + +/** + * ips_detect_cpu - detect whether CPU supports IPS + * + * Walk our list and see if we're on a supported CPU. If we find one, + * return the limits for it. + */ +static struct ips_mcp_limits *ips_detect_cpu(struct ips_driver *ips) +{ + u64 turbo_power, misc_en; + struct ips_mcp_limits *limits = NULL; + u16 tdp; + + if (!(boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model == 37)) { + dev_info(&ips->dev->dev, "Non-IPS CPU detected.\n"); + goto out; + } + + rdmsrl(IA32_MISC_ENABLE, misc_en); + /* + * If the turbo enable bit isn't set, we shouldn't try to enable/disable + * turbo manually or we'll get an illegal MSR access, even though + * turbo will still be available. + */ + if (!(misc_en & IA32_MISC_TURBO_EN)) + ; /* add turbo MSR write allowed flag if necessary */ + + if (strstr(boot_cpu_data.x86_model_id, "CPU M")) + limits = &ips_sv_limits; + else if (strstr(boot_cpu_data.x86_model_id, "CPU L")) + limits = &ips_lv_limits; + else if (strstr(boot_cpu_data.x86_model_id, "CPU U")) + limits = &ips_ulv_limits; + else + dev_info(&ips->dev->dev, "No CPUID match found.\n"); + + rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_power); + tdp = turbo_power & TURBO_TDP_MASK; + + /* Sanity check TDP against CPU */ + if (limits->mcp_power_limit != (tdp / 8) * 1000) { + dev_warn(&ips->dev->dev, "Warning: CPU TDP doesn't match expected value (found %d, expected %d)\n", + tdp / 8, limits->mcp_power_limit / 1000); + } + +out: + return limits; +} + +/** + * ips_get_i915_syms - try to get GPU control methods from i915 driver + * @ips: IPS driver + * + * The i915 driver exports several interfaces to allow the IPS driver to + * monitor and control graphics turbo mode. If we can find them, we can + * enable graphics turbo, otherwise we must disable it to avoid exceeding + * thermal and power limits in the MCP. + */ +static bool ips_get_i915_syms(struct ips_driver *ips) +{ + ips->read_mch_val = symbol_get(i915_read_mch_val); + if (!ips->read_mch_val) + goto out_err; + ips->gpu_raise = symbol_get(i915_gpu_raise); + if (!ips->gpu_raise) + goto out_put_mch; + ips->gpu_lower = symbol_get(i915_gpu_lower); + if (!ips->gpu_lower) + goto out_put_raise; + ips->gpu_busy = symbol_get(i915_gpu_busy); + if (!ips->gpu_busy) + goto out_put_lower; + ips->gpu_turbo_disable = symbol_get(i915_gpu_turbo_disable); + if (!ips->gpu_turbo_disable) + goto out_put_busy; + + return true; + +out_put_busy: + symbol_put(i915_gpu_turbo_disable); +out_put_lower: + symbol_put(i915_gpu_lower); +out_put_raise: + symbol_put(i915_gpu_raise); +out_put_mch: + symbol_put(i915_read_mch_val); +out_err: + return false; +} + +static DEFINE_PCI_DEVICE_TABLE(ips_id_table) = { + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, + PCI_DEVICE_ID_INTEL_THERMAL_SENSOR), }, + { 0, } +}; + +MODULE_DEVICE_TABLE(pci, ips_id_table); + +static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) +{ + u64 platform_info; + struct ips_driver *ips; + u32 hts; + int ret = 0; + u16 htshi, trc, trc_required_mask; + u8 tse; + + ips = kzalloc(sizeof(struct ips_driver), GFP_KERNEL); + if (!ips) + return -ENOMEM; + + pci_set_drvdata(dev, ips); + ips->dev = dev; + + ips->limits = ips_detect_cpu(ips); + if (!ips->limits) { + dev_info(&dev->dev, "IPS not supported on this CPU\n"); + ret = -ENXIO; + goto error_free; + } + + spin_lock_init(&ips->turbo_status_lock); + + if (!pci_resource_start(dev, 0)) { + dev_err(&dev->dev, "TBAR not assigned, aborting\n"); + ret = -ENXIO; + goto error_free; + } + + ret = pci_request_regions(dev, "ips thermal sensor"); + if (ret) { + dev_err(&dev->dev, "thermal resource busy, aborting\n"); + goto error_free; + } + + ret = pci_enable_device(dev); + if (ret) { + dev_err(&dev->dev, "can't enable PCI device, aborting\n"); + goto error_free; + } + + ips->regmap = ioremap(pci_resource_start(dev, 0), + pci_resource_len(dev, 0)); + if (!ips->regmap) { + dev_err(&dev->dev, "failed to map thermal regs, aborting\n"); + ret = -EBUSY; + goto error_release; + } + + tse = thm_readb(THM_TSE); + if (tse != TSE_EN) { + dev_err(&dev->dev, "thermal device not enabled (0x%02x), aborting\n", tse); + ret = -ENXIO; + goto error_unmap; + } + + trc = thm_readw(THM_TRC); + trc_required_mask = TRC_CORE1_EN | TRC_CORE_PWR | TRC_MCH_EN; + if ((trc & trc_required_mask) != trc_required_mask) { + dev_err(&dev->dev, "thermal reporting for required devices not enabled, aborting\n"); + ret = -ENXIO; + goto error_unmap; + } + + if (trc & TRC_CORE2_EN) + ips->second_cpu = true; + + if (!ips_get_i915_syms(ips)) { + dev_err(&dev->dev, "failed to get i915 symbols, graphics turbo disabled\n"); + ips->gpu_turbo_enabled = false; + } else { + dev_dbg(&dev->dev, "graphics turbo enabled\n"); + ips->gpu_turbo_enabled = true; + } + + update_turbo_limits(ips); + dev_dbg(&dev->dev, "max cpu power clamp: %dW\n", + ips->mcp_power_limit / 10); + dev_dbg(&dev->dev, "max core power clamp: %dW\n", + ips->core_power_limit / 10); + /* BIOS may update limits at runtime */ + if (thm_readl(THM_PSC) & PSP_PBRT) + ips->poll_turbo_status = true; + + /* + * Check PLATFORM_INFO MSR to make sure this chip is + * turbo capable. + */ + rdmsrl(PLATFORM_INFO, platform_info); + if (!(platform_info & PLATFORM_TDP)) { + dev_err(&dev->dev, "platform indicates TDP override unavailable, aborting\n"); + ret = -ENODEV; + goto error_unmap; + } + + /* + * IRQ handler for ME interaction + * Note: don't use MSI here as the PCH has bugs. + */ + pci_disable_msi(dev); + ret = request_irq(dev->irq, ips_irq_handler, IRQF_SHARED, "ips", + ips); + if (ret) { + dev_err(&dev->dev, "request irq failed, aborting\n"); + goto error_unmap; + } + + /* Enable aux, hot & critical interrupts */ + thm_writeb(THM_TSPIEN, TSPIEN_AUX2_LOHI | TSPIEN_CRIT_LOHI | + TSPIEN_HOT_LOHI | TSPIEN_AUX_LOHI); + thm_writeb(THM_TEN, TEN_UPDATE_EN); + + /* Collect adjustment values */ + ips->cta_val = thm_readw(THM_CTA); + ips->pta_val = thm_readw(THM_PTA); + ips->mgta_val = thm_readw(THM_MGTA); + + /* Save turbo limits & ratios */ + rdmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); + + ips_enable_cpu_turbo(ips); + ips->cpu_turbo_enabled = true; + + /* Set up the work queue and monitor/adjust threads */ + ips->monitor = kthread_run(ips_monitor, ips, "ips-monitor"); + if (IS_ERR(ips->monitor)) { + dev_err(&dev->dev, + "failed to create thermal monitor thread, aborting\n"); + ret = -ENOMEM; + goto error_free_irq; + } + + ips->adjust = kthread_create(ips_adjust, ips, "ips-adjust"); + if (IS_ERR(ips->adjust)) { + dev_err(&dev->dev, + "failed to create thermal adjust thread, aborting\n"); + ret = -ENOMEM; + goto error_thread_cleanup; + } + + hts = (ips->core_power_limit << HTS_PCPL_SHIFT) | + (ips->mcp_temp_limit << HTS_PTL_SHIFT) | HTS_NVV; + htshi = HTS2_PRST_RUNNING << HTS2_PRST_SHIFT; + + thm_writew(THM_HTSHI, htshi); + thm_writel(THM_HTS, hts); + + ips_debugfs_init(ips); + + dev_info(&dev->dev, "IPS driver initialized, MCP temp limit %d\n", + ips->mcp_temp_limit); + return ret; + +error_thread_cleanup: + kthread_stop(ips->monitor); +error_free_irq: + free_irq(ips->dev->irq, ips); +error_unmap: + iounmap(ips->regmap); +error_release: + pci_release_regions(dev); +error_free: + kfree(ips); + return ret; +} + +static void ips_remove(struct pci_dev *dev) +{ + struct ips_driver *ips = pci_get_drvdata(dev); + u64 turbo_override; + + if (!ips) + return; + + ips_debugfs_cleanup(ips); + + /* Release i915 driver */ + if (ips->read_mch_val) + symbol_put(i915_read_mch_val); + if (ips->gpu_raise) + symbol_put(i915_gpu_raise); + if (ips->gpu_lower) + symbol_put(i915_gpu_lower); + if (ips->gpu_busy) + symbol_put(i915_gpu_busy); + if (ips->gpu_turbo_disable) + symbol_put(i915_gpu_turbo_disable); + + rdmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); + turbo_override &= ~(TURBO_TDC_OVR_EN | TURBO_TDP_OVR_EN); + wrmsrl(TURBO_POWER_CURRENT_LIMIT, turbo_override); + wrmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); + + free_irq(ips->dev->irq, ips); + if (ips->adjust) + kthread_stop(ips->adjust); + if (ips->monitor) + kthread_stop(ips->monitor); + iounmap(ips->regmap); + pci_release_regions(dev); + kfree(ips); + dev_dbg(&dev->dev, "IPS driver removed\n"); +} + +#ifdef CONFIG_PM +static int ips_suspend(struct pci_dev *dev, pm_message_t state) +{ + return 0; +} + +static int ips_resume(struct pci_dev *dev) +{ + return 0; +} +#else +#define ips_suspend NULL +#define ips_resume NULL +#endif /* CONFIG_PM */ + +static void ips_shutdown(struct pci_dev *dev) +{ +} + +static struct pci_driver ips_pci_driver = { + .name = "intel ips", + .id_table = ips_id_table, + .probe = ips_probe, + .remove = ips_remove, + .suspend = ips_suspend, + .resume = ips_resume, + .shutdown = ips_shutdown, +}; + +static int __init ips_init(void) +{ + return pci_register_driver(&ips_pci_driver); +} +module_init(ips_init); + +static void ips_exit(void) +{ + pci_unregister_driver(&ips_pci_driver); + return; +} +module_exit(ips_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Jesse Barnes "); +MODULE_DESCRIPTION("Intelligent Power Sharing Driver"); diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h index 7f0028e..8f8b072 100644 --- a/include/drm/i915_drm.h +++ b/include/drm/i915_drm.h @@ -33,6 +33,15 @@ * subject to backwards-compatibility constraints. */ +#ifdef __KERNEL__ +/* For use by IPS driver */ +extern unsigned long i915_read_mch_val(void); +extern bool i915_gpu_raise(void); +extern bool i915_gpu_lower(void); +extern bool i915_gpu_busy(void); +extern bool i915_gpu_turbo_disable(void); +#endif + /* Each region is a minimum of 16k, and there are at most 255 of them. */ #define I915_NR_TEX_REGIONS 255 /* table size 2k - maximum due to use -- cgit v0.10.2 From 0385e5210c83b13fe685c54b6063655f80bce3ee Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Thu, 20 May 2010 14:27:23 -0700 Subject: IPS driver: add GPU busy and turbo checking Be sure to enable GPU turbo by default at load time and check GPU busy and MCP exceeded status correctly. Also fix up CPU power comparison and work around buggy MCH temp reporting. Signed-off-by: Jesse Barnes Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c index f1dce3b..cdaf40e 100644 --- a/drivers/platform/x86/intel_ips.c +++ b/drivers/platform/x86/intel_ips.c @@ -515,7 +515,10 @@ static void ips_disable_cpu_turbo(struct ips_driver *ips) */ static bool ips_gpu_busy(struct ips_driver *ips) { - return false; + if (!ips->gpu_turbo_enabled) + return false; + + return ips->gpu_busy(); } /** @@ -627,7 +630,7 @@ static bool cpu_exceeded(struct ips_driver *ips, int cpu) avg = cpu ? ips->ctv2_avg_temp : ips->ctv1_avg_temp; if (avg > (ips->limits->core_temp_limit * 100)) ret = true; - if (ips->cpu_avg_power > ips->core_power_limit) + if (ips->cpu_avg_power > ips->core_power_limit * 100) ret = true; spin_unlock_irqrestore(&ips->turbo_status_lock, flags); @@ -652,6 +655,8 @@ static bool mch_exceeded(struct ips_driver *ips) spin_lock_irqsave(&ips->turbo_status_lock, flags); if (ips->mch_avg_temp > (ips->limits->mch_temp_limit * 100)) ret = true; + if (ips->mch_avg_power > ips->mch_power_limit) + ret = true; spin_unlock_irqrestore(&ips->turbo_status_lock, flags); return ret; @@ -747,7 +752,7 @@ static int ips_adjust(void *data) ips_disable_gpu_turbo(ips); /* We're outside our comfort zone, crank them down */ - if (!mcp_exceeded(ips)) { + if (mcp_exceeded(ips)) { ips_cpu_lower(ips); ips_gpu_lower(ips); goto sleep; @@ -808,8 +813,7 @@ static u16 read_mgtv(struct ips_driver *ips) ret = ((val * slope + 0x40) >> 7) + offset; - - return ret; + return 0; /* MCH temp reporting buggy */ } static u16 read_ptv(struct ips_driver *ips) @@ -1471,14 +1475,6 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) if (trc & TRC_CORE2_EN) ips->second_cpu = true; - if (!ips_get_i915_syms(ips)) { - dev_err(&dev->dev, "failed to get i915 symbols, graphics turbo disabled\n"); - ips->gpu_turbo_enabled = false; - } else { - dev_dbg(&dev->dev, "graphics turbo enabled\n"); - ips->gpu_turbo_enabled = true; - } - update_turbo_limits(ips); dev_dbg(&dev->dev, "max cpu power clamp: %dW\n", ips->mcp_power_limit / 10); @@ -1488,6 +1484,14 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id) if (thm_readl(THM_PSC) & PSP_PBRT) ips->poll_turbo_status = true; + if (!ips_get_i915_syms(ips)) { + dev_err(&dev->dev, "failed to get i915 symbols, graphics turbo disabled\n"); + ips->gpu_turbo_enabled = false; + } else { + dev_dbg(&dev->dev, "graphics turbo enabled\n"); + ips->gpu_turbo_enabled = true; + } + /* * Check PLATFORM_INFO MSR to make sure this chip is * turbo capable. -- cgit v0.10.2 From b95d13eaf3d4ea093aba95c7f615f3b10708a2c4 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Wed, 9 Jun 2010 16:48:39 -0300 Subject: classmate-laptop: should check for NULL as retval for rfkill_alloc rfkill_alloc returns NULL when it fails if RFKILL is enabled. When RFKILL is disabled, its return value of ERR_PTR(-ENODEV) is OK to use as all rfkill functions will work with it, as they are simply empty stubs. Reported-by: Alan Jenkins Cc: Johannes Berg Cc: platform-driver-x86@vger.kernel.org Cc: mjg@redhat.com Cc: don@syst.com.br Cc: rpurdie@rpsys.net Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c index 3bf399f..73ea76e 100644 --- a/drivers/platform/x86/classmate-laptop.c +++ b/drivers/platform/x86/classmate-laptop.c @@ -573,16 +573,17 @@ static int cmpc_ipml_add(struct acpi_device *acpi) ipml->rf = rfkill_alloc("cmpc_rfkill", &acpi->dev, RFKILL_TYPE_WLAN, &cmpc_rfkill_ops, acpi->handle); - /* rfkill_alloc may fail if RFKILL is disabled. We should still work - * anyway. */ - if (!IS_ERR(ipml->rf)) { + /* + * If RFKILL is disabled, rfkill_alloc will return ERR_PTR(-ENODEV). + * This is OK, however, since all other uses of the device will not + * derefence it. + */ + if (ipml->rf) { retval = rfkill_register(ipml->rf); if (retval) { rfkill_destroy(ipml->rf); ipml->rf = NULL; } - } else { - ipml->rf = NULL; } dev_set_drvdata(&acpi->dev, ipml); -- cgit v0.10.2 From 35f2915c3bd0cd6950bdd9d461de565e8feae852 Mon Sep 17 00:00:00 2001 From: Feng Tang Date: Tue, 1 Jun 2010 13:07:34 +0100 Subject: intel_scu_ipc: add definitions for vRTC related command Signed-off-by: Feng Tang Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/arch/x86/include/asm/intel_scu_ipc.h b/arch/x86/include/asm/intel_scu_ipc.h index 4470c9a..0320045 100644 --- a/arch/x86/include/asm/intel_scu_ipc.h +++ b/arch/x86/include/asm/intel_scu_ipc.h @@ -1,6 +1,12 @@ #ifndef _ASM_X86_INTEL_SCU_IPC_H_ #define _ASM_X86_INTEL_SCU_IPC_H_ +#define IPCMSG_VRTC 0xFA /* Set vRTC device */ + +/* Command id associated with message IPCMSG_VRTC */ +#define IPC_CMD_VRTC_SETTIME 1 /* Set time */ +#define IPC_CMD_VRTC_SETALARM 2 /* Set alarm */ + /* Read single register */ int intel_scu_ipc_ioread8(u16 addr, u8 *data); -- cgit v0.10.2 From dfec5c48cdfdcb08d73d24cbf277de543ef864ae Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 10 Jun 2010 16:06:40 +0800 Subject: hp-wmi: add error handling for hp_wmi_init Current implementation in hp_wmi_init does not check any error and always return success. This patch properly handles recource reclaim and return err in error path. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index d81f4cf..9498bdd 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -715,23 +715,42 @@ static int __init hp_wmi_init(void) if (wmi_has_guid(HPWMI_EVENT_GUID)) { err = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL); - if (ACPI_SUCCESS(err)) - hp_wmi_input_setup(); + if (ACPI_FAILURE(err)) + return -EINVAL; + err = hp_wmi_input_setup(); + if (err) { + wmi_remove_notify_handler(HPWMI_EVENT_GUID); + return err; + } } if (wmi_has_guid(HPWMI_BIOS_GUID)) { err = platform_driver_register(&hp_wmi_driver); if (err) - return 0; + goto err_driver_reg; hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); if (!hp_wmi_platform_dev) { - platform_driver_unregister(&hp_wmi_driver); - return 0; + err = -ENOMEM; + goto err_device_alloc; } - platform_device_add(hp_wmi_platform_dev); + err = platform_device_add(hp_wmi_platform_dev); + if (err) + goto err_device_add; } return 0; + +err_device_add: + platform_device_put(hp_wmi_platform_dev); +err_device_alloc: + platform_driver_unregister(&hp_wmi_driver); +err_driver_reg: + if (wmi_has_guid(HPWMI_EVENT_GUID)) { + input_unregister_device(hp_wmi_input_dev); + wmi_remove_notify_handler(HPWMI_EVENT_GUID); + } + + return err; } static void __exit hp_wmi_exit(void) -- cgit v0.10.2 From e9ec7f3539cbeae8ffc5d7b30543e5612df5cba3 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Mon, 21 Jun 2010 17:40:15 +0200 Subject: X86: intel_ips, check for kzalloc properly Stanse found that there are two NULL checks missing in ips_monitor. So check their value too and bail out appropriately if the allocation failed. While at it, add one more kfree to the fail path. It is not necessary now, but may be needed in the future when a new allocation is added. And for completeness. Also remove unneeded initialization of the variables. They are all set right after their declaration. Signed-off-by: Jiri Slaby Signed-off-by: Matthew Garrett Acked-by: Jesse Barnes diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c index cdaf40e..0344822 100644 --- a/drivers/platform/x86/intel_ips.c +++ b/drivers/platform/x86/intel_ips.c @@ -920,9 +920,8 @@ static int ips_monitor(void *data) struct timer_list timer; unsigned long seqno_timestamp, expire, last_msecs, last_sample_period; int i; - u32 *cpu_samples = NULL, *mchp_samples = NULL, old_cpu_power; - u16 *mcp_samples = NULL, *ctv1_samples = NULL, *ctv2_samples = NULL, - *mch_samples = NULL; + u32 *cpu_samples, *mchp_samples, old_cpu_power; + u16 *mcp_samples, *ctv1_samples, *ctv2_samples, *mch_samples; u8 cur_seqno, last_seqno; mcp_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); @@ -931,7 +930,8 @@ static int ips_monitor(void *data) mch_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); cpu_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL); mchp_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL); - if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples) { + if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples || + !cpu_samples || !mchp_samples) { dev_err(&ips->dev->dev, "failed to allocate sample array, ips disabled\n"); kfree(mcp_samples); @@ -939,6 +939,7 @@ static int ips_monitor(void *data) kfree(ctv2_samples); kfree(mch_samples); kfree(cpu_samples); + kfree(mchp_samples); kthread_stop(ips->adjust); return -ENOMEM; } -- cgit v0.10.2 From 1c79632bd011de84f32dcdf7d92b65bb61b1e6da Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 22 Jun 2010 16:17:38 +0800 Subject: acer-wmi: fix resource reclaim in acer_wmi_init error path This patch fixes the resource reclaim in acer_wmi_init error path. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index 1ea6c43..ae79624 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -1327,22 +1327,31 @@ static int __init acer_wmi_init(void) "generic video driver\n"); } - if (platform_driver_register(&acer_platform_driver)) { + err = platform_driver_register(&acer_platform_driver); + if (err) { printk(ACER_ERR "Unable to register platform driver.\n"); goto error_platform_register; } + acer_platform_device = platform_device_alloc("acer-wmi", -1); - platform_device_add(acer_platform_device); + if (!acer_platform_device) { + err = -ENOMEM; + goto error_device_alloc; + } + + err = platform_device_add(acer_platform_device); + if (err) + goto error_device_add; err = create_sysfs(); if (err) - return err; + goto error_create_sys; if (wmi_has_guid(WMID_GUID2)) { interface->debug.wmid_devices = get_wmid_devices(); err = create_debugfs(); if (err) - return err; + goto error_create_debugfs; } /* Override any initial settings with values from the commandline */ @@ -1350,8 +1359,16 @@ static int __init acer_wmi_init(void) return 0; +error_create_debugfs: + remove_sysfs(acer_platform_device); +error_create_sys: + platform_device_del(acer_platform_device); +error_device_add: + platform_device_put(acer_platform_device); +error_device_alloc: + platform_driver_unregister(&acer_platform_driver); error_platform_register: - return -ENODEV; + return err; } static void __exit acer_wmi_exit(void) -- cgit v0.10.2 From 410d44c74cf9942e3055d5b7d73953fac8efbacb Mon Sep 17 00:00:00 2001 From: Rezwanul Kabir Date: Wed, 23 Jun 2010 12:02:43 -0500 Subject: dell-laptop: Add another Dell laptop family to the DMI whitelist This is to support Precision M4500 and others. Signed-off-by: Rezwanul Kabir Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c index 661e3ac..9238218 100644 --- a/drivers/platform/x86/dell-laptop.c +++ b/drivers/platform/x86/dell-laptop.c @@ -83,6 +83,12 @@ static const struct dmi_system_id __initdata dell_device_table[] = { }, }, { + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/ + }, + }, + { .ident = "Dell Computer Corporation", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), @@ -621,4 +627,5 @@ MODULE_AUTHOR("Matthew Garrett "); MODULE_DESCRIPTION("Dell laptop driver"); MODULE_LICENSE("GPL"); MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*"); +MODULE_ALIAS("dmi:*svnDellInc.:*:ct9:*"); MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*"); -- cgit v0.10.2 From a5167c5b3a842b865b0ca87202b95cc8a84c9e7e Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 3 Jun 2010 11:45:45 +0800 Subject: wmi: fix memory leak in parse_wdg This patch properly kfree out.pointer and gblock in error path. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index e4eaa14..582b5cd 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -827,8 +827,10 @@ static __init acpi_status parse_wdg(acpi_handle handle) total = obj->buffer.length / sizeof(struct guid_block); gblock = kmemdup(obj->buffer.pointer, obj->buffer.length, GFP_KERNEL); - if (!gblock) - return AE_NO_MEMORY; + if (!gblock) { + status = AE_NO_MEMORY; + goto out_free_pointer; + } for (i = 0; i < total; i++) { /* @@ -848,8 +850,10 @@ static __init acpi_status parse_wdg(acpi_handle handle) wmi_dump_wdg(&gblock[i]); wblock = kzalloc(sizeof(struct wmi_block), GFP_KERNEL); - if (!wblock) - return AE_NO_MEMORY; + if (!wblock) { + status = AE_NO_MEMORY; + goto out_free_gblock; + } wblock->gblock = gblock[i]; wblock->handle = handle; @@ -860,8 +864,10 @@ static __init acpi_status parse_wdg(acpi_handle handle) list_add_tail(&wblock->list, &wmi_blocks.list); } - kfree(out.pointer); +out_free_gblock: kfree(gblock); +out_free_pointer: + kfree(out.pointer); return status; } -- cgit v0.10.2 From 97ba0af097dc3428b85dc6a1282968d7ba9510f5 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 3 Jun 2010 15:18:03 +0800 Subject: acer-wmi/hp-wmi: use platform_device_unregister instead of platform_device_del in module_exit platform_device_unregister will also call platform_device_put() to drop reference count. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index ae79624..56e6f10 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -1375,7 +1375,7 @@ static void __exit acer_wmi_exit(void) { remove_sysfs(acer_platform_device); remove_debugfs(); - platform_device_del(acer_platform_device); + platform_device_unregister(acer_platform_device); platform_driver_unregister(&acer_platform_driver); printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n"); diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 9498bdd..d55bf58 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -760,7 +760,7 @@ static void __exit hp_wmi_exit(void) input_unregister_device(hp_wmi_input_dev); } if (hp_wmi_platform_dev) { - platform_device_del(hp_wmi_platform_dev); + platform_device_unregister(hp_wmi_platform_dev); platform_driver_unregister(&hp_wmi_driver); } } -- cgit v0.10.2 From c715a38bb7fc22fb8018b916c8a9f7ff017a8ad7 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Fri, 18 Jun 2010 14:05:52 +0100 Subject: rar: Move the RAR driver into the right place as its now clean We exit staging rar! rar! rar!... Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett Acked-by: Greg Kroah-Hartman diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 724b2ed..2f173bc 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -539,6 +539,28 @@ config INTEL_SCU_IPC some embedded Intel x86 platforms. This is not needed for PC-type machines. +config RAR_REGISTER + bool "Restricted Access Region Register Driver" + depends on PCI && X86_MRST + default n + ---help--- + This driver allows other kernel drivers access to the + contents of the restricted access region control registers. + + The restricted access region control registers + (rar_registers) are used to pass address and + locking information on restricted access regions + to other drivers that use restricted access regions. + + The restricted access regions are regions of memory + on the Intel MID Platform that are not accessible to + the x86 processor, but are accessible to dedicated + processors on board peripheral devices. + + The purpose of the restricted access regions is to + protect sensitive data from compromise by unauthorized + programs running on the x86 processor. + config INTEL_IPS tristate "Intel Intelligent Power Sharing" depends on ACPI diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index 7318fc2..ed50eca 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -26,4 +26,5 @@ obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o obj-$(CONFIG_ACPI_TOSHIBA) += toshiba_acpi.o obj-$(CONFIG_TOSHIBA_BT_RFKILL) += toshiba_bluetooth.o obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o +obj-$(CONFIG_RAR_REGISTER) += intel_rar_register.o obj-$(CONFIG_INTEL_IPS) += intel_ips.o diff --git a/drivers/platform/x86/intel_rar_register.c b/drivers/platform/x86/intel_rar_register.c new file mode 100644 index 0000000..73f8e6d --- /dev/null +++ b/drivers/platform/x86/intel_rar_register.c @@ -0,0 +1,671 @@ +/* + * rar_register.c - An Intel Restricted Access Region register driver + * + * Copyright(c) 2009 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ------------------------------------------------------------------- + * 20091204 Mark Allyn + * Ossama Othman + * Cleanup per feedback from Alan Cox and Arjan Van De Ven + * + * 20090806 Ossama Othman + * Return zero high address if upper 22 bits is zero. + * Cleaned up checkpatch errors. + * Clarified that driver is dealing with bus addresses. + * + * 20090702 Ossama Othman + * Removed unnecessary include directives + * Cleaned up spinlocks. + * Cleaned up logging. + * Improved invalid parameter checks. + * Fixed and simplified RAR address retrieval and RAR locking + * code. + * + * 20090626 Mark Allyn + * Initial publish + */ + +#include +#include +#include +#include +#include +#include + +/* === Lincroft Message Bus Interface === */ +#define LNC_MCR_OFFSET 0xD0 /* Message Control Register */ +#define LNC_MDR_OFFSET 0xD4 /* Message Data Register */ + +/* Message Opcodes */ +#define LNC_MESSAGE_READ_OPCODE 0xD0 +#define LNC_MESSAGE_WRITE_OPCODE 0xE0 + +/* Message Write Byte Enables */ +#define LNC_MESSAGE_BYTE_WRITE_ENABLES 0xF + +/* B-unit Port */ +#define LNC_BUNIT_PORT 0x3 + +/* === Lincroft B-Unit Registers - Programmed by IA32 firmware === */ +#define LNC_BRAR0L 0x10 +#define LNC_BRAR0H 0x11 +#define LNC_BRAR1L 0x12 +#define LNC_BRAR1H 0x13 +/* Reserved for SeP */ +#define LNC_BRAR2L 0x14 +#define LNC_BRAR2H 0x15 + +/* Moorestown supports three restricted access regions. */ +#define MRST_NUM_RAR 3 + +/* RAR Bus Address Range */ +struct rar_addr { + dma_addr_t low; + dma_addr_t high; +}; + +/* + * We create one of these for each RAR + */ +struct client { + int (*callback)(unsigned long data); + unsigned long driver_priv; + bool busy; +}; + +static DEFINE_MUTEX(rar_mutex); +static DEFINE_MUTEX(lnc_reg_mutex); + +/* + * One per RAR device (currently only one device) + */ +struct rar_device { + struct rar_addr rar_addr[MRST_NUM_RAR]; + struct pci_dev *rar_dev; + bool registered; + bool allocated; + struct client client[MRST_NUM_RAR]; +}; + +/* Current platforms have only one rar_device for 3 rar regions */ +static struct rar_device my_rar_device; + +/* + * Abstract out multiple device support. Current platforms only + * have a single RAR device. + */ + +/** + * alloc_rar_device - return a new RAR structure + * + * Return a new (but not yet ready) RAR device object + */ +static struct rar_device *alloc_rar_device(void) +{ + if (my_rar_device.allocated) + return NULL; + my_rar_device.allocated = 1; + return &my_rar_device; +} + +/** + * free_rar_device - free a RAR object + * @rar: the RAR device being freed + * + * Release a RAR object and any attached resources + */ +static void free_rar_device(struct rar_device *rar) +{ + pci_dev_put(rar->rar_dev); + rar->allocated = 0; +} + +/** + * _rar_to_device - return the device handling this RAR + * @rar: RAR number + * @off: returned offset + * + * Internal helper for looking up RAR devices. This and alloc are the + * two functions that need touching to go to multiple RAR devices. + */ +static struct rar_device *_rar_to_device(int rar, int *off) +{ + if (rar >= 0 && rar <= 3) { + *off = rar; + return &my_rar_device; + } + return NULL; +} + +/** + * rar_to_device - return the device handling this RAR + * @rar: RAR number + * @off: returned offset + * + * Return the device this RAR maps to if one is present, otherwise + * returns NULL. Reports the offset relative to the base of this + * RAR device in off. + */ +static struct rar_device *rar_to_device(int rar, int *off) +{ + struct rar_device *rar_dev = _rar_to_device(rar, off); + if (rar_dev == NULL || !rar_dev->registered) + return NULL; + return rar_dev; +} + +/** + * rar_to_client - return the client handling this RAR + * @rar: RAR number + * + * Return the client this RAR maps to if a mapping is known, otherwise + * returns NULL. + */ +static struct client *rar_to_client(int rar) +{ + int idx; + struct rar_device *r = _rar_to_device(rar, &idx); + if (r != NULL) + return &r->client[idx]; + return NULL; +} + +/** + * rar_read_addr - retrieve a RAR mapping + * @pdev: PCI device for the RAR + * @offset: offset for message + * @addr: returned address + * + * Reads the address of a given RAR register. Returns 0 on success + * or an error code on failure. + */ +static int rar_read_addr(struct pci_dev *pdev, int offset, dma_addr_t *addr) +{ + /* + * ======== The Lincroft Message Bus Interface ======== + * Lincroft registers may be obtained via PCI from + * the host bridge using the Lincroft Message Bus + * Interface. That message bus interface is generally + * comprised of two registers: a control register (MCR, 0xDO) + * and a data register (MDR, 0xD4). + * + * The MCR (message control register) format is the following: + * 1. [31:24]: Opcode + * 2. [23:16]: Port + * 3. [15:8]: Register Offset + * 4. [7:4]: Byte Enables (use 0xF to set all of these bits + * to 1) + * 5. [3:0]: reserved + * + * Read (0xD0) and write (0xE0) opcodes are written to the + * control register when reading and writing to Lincroft + * registers, respectively. + * + * We're interested in registers found in the Lincroft + * B-unit. The B-unit port is 0x3. + * + * The six B-unit RAR register offsets we use are listed + * earlier in this file. + * + * Lastly writing to the MCR register requires the "Byte + * enables" bits to be set to 1. This may be achieved by + * writing 0xF at bit 4. + * + * The MDR (message data register) format is the following: + * 1. [31:0]: Read/Write Data + * + * Data being read from this register is only available after + * writing the appropriate control message to the MCR + * register. + * + * Data being written to this register must be written before + * writing the appropriate control message to the MCR + * register. + */ + + int result; + u32 addr32; + + /* Construct control message */ + u32 const message = + (LNC_MESSAGE_READ_OPCODE << 24) + | (LNC_BUNIT_PORT << 16) + | (offset << 8) + | (LNC_MESSAGE_BYTE_WRITE_ENABLES << 4); + + dev_dbg(&pdev->dev, "Offset for 'get' LNC MSG is %x\n", offset); + + /* + * We synchronize access to the Lincroft MCR and MDR registers + * until BOTH the command is issued through the MCR register + * and the corresponding data is read from the MDR register. + * Otherwise a race condition would exist between accesses to + * both registers. + */ + + mutex_lock(&lnc_reg_mutex); + + /* Send the control message */ + result = pci_write_config_dword(pdev, LNC_MCR_OFFSET, message); + if (!result) { + /* Read back the address as a 32bit value */ + result = pci_read_config_dword(pdev, LNC_MDR_OFFSET, &addr32); + *addr = (dma_addr_t)addr32; + } + mutex_unlock(&lnc_reg_mutex); + return result; +} + +/** + * rar_set_addr - Set a RAR mapping + * @pdev: PCI device for the RAR + * @offset: offset for message + * @addr: address to set + * + * Sets the address of a given RAR register. Returns 0 on success + * or an error code on failure. + */ +static int rar_set_addr(struct pci_dev *pdev, + int offset, + dma_addr_t addr) +{ + /* + * Data being written to this register must be written before + * writing the appropriate control message to the MCR + * register. + * See rar_get_addrs() for a description of the + * message bus interface being used here. + */ + + int result; + + /* Construct control message */ + u32 const message = (LNC_MESSAGE_WRITE_OPCODE << 24) + | (LNC_BUNIT_PORT << 16) + | (offset << 8) + | (LNC_MESSAGE_BYTE_WRITE_ENABLES << 4); + + /* + * We synchronize access to the Lincroft MCR and MDR registers + * until BOTH the command is issued through the MCR register + * and the corresponding data is read from the MDR register. + * Otherwise a race condition would exist between accesses to + * both registers. + */ + + mutex_lock(&lnc_reg_mutex); + + /* Send the control message */ + result = pci_write_config_dword(pdev, LNC_MDR_OFFSET, addr); + if (!result) + /* And address */ + result = pci_write_config_dword(pdev, LNC_MCR_OFFSET, message); + + mutex_unlock(&lnc_reg_mutex); + return result; +} + +/* + * rar_init_params - Initialize RAR parameters + * @rar: RAR device to initialise + * + * Initialize RAR parameters, such as bus addresses, etc. Returns 0 + * on success, or an error code on failure. + */ +static int init_rar_params(struct rar_device *rar) +{ + struct pci_dev *pdev = rar->rar_dev; + unsigned int i; + int result = 0; + int offset = 0x10; /* RAR 0 to 2 in order low/high/low/high/... */ + + /* Retrieve RAR start and end bus addresses. + * Access the RAR registers through the Lincroft Message Bus + * Interface on PCI device: 00:00.0 Host bridge. + */ + + for (i = 0; i < MRST_NUM_RAR; ++i) { + struct rar_addr *addr = &rar->rar_addr[i]; + + result = rar_read_addr(pdev, offset++, &addr->low); + if (result != 0) + return result; + + result = rar_read_addr(pdev, offset++, &addr->high); + if (result != 0) + return result; + + + /* + * Only the upper 22 bits of the RAR addresses are + * stored in their corresponding RAR registers so we + * must set the lower 10 bits accordingly. + + * The low address has its lower 10 bits cleared, and + * the high address has all its lower 10 bits set, + * e.g.: + * low = 0x2ffffc00 + */ + + addr->low &= (dma_addr_t)0xfffffc00u; + + /* + * Set bits 9:0 on uppser address if bits 31:10 are non + * zero; otherwize clear all bits + */ + + if ((addr->high & 0xfffffc00u) == 0) + addr->high = 0; + else + addr->high |= 0x3ffu; + } + /* Done accessing the device. */ + + if (result == 0) { + for (i = 0; i != MRST_NUM_RAR; ++i) { + /* + * "BRAR" refers to the RAR registers in the + * Lincroft B-unit. + */ + dev_info(&pdev->dev, "BRAR[%u] bus address range = " + "[%lx, %lx]\n", i, + (unsigned long)rar->rar_addr[i].low, + (unsigned long)rar->rar_addr[i].high); + } + } + return result; +} + +/** + * rar_get_address - get the bus address in a RAR + * @start: return value of start address of block + * @end: return value of end address of block + * + * The rar_get_address function is used by other device drivers + * to obtain RAR address information on a RAR. It takes three + * parameters: + * + * The function returns a 0 upon success or an error if there is no RAR + * facility on this system. + */ +int rar_get_address(int rar_index, dma_addr_t *start, dma_addr_t *end) +{ + int idx; + struct rar_device *rar = rar_to_device(rar_index, &idx); + + if (rar == NULL) { + WARN_ON(1); + return -ENODEV; + } + + *start = rar->rar_addr[idx].low; + *end = rar->rar_addr[idx].high; + return 0; +} +EXPORT_SYMBOL(rar_get_address); + +/** + * rar_lock - lock a RAR register + * @rar_index: RAR to lock (0-2) + * + * The rar_lock function is ued by other device drivers to lock an RAR. + * once a RAR is locked, it stays locked until the next system reboot. + * + * The function returns a 0 upon success or an error if there is no RAR + * facility on this system, or the locking fails + */ +int rar_lock(int rar_index) +{ + struct rar_device *rar; + int result; + int idx; + dma_addr_t low, high; + + rar = rar_to_device(rar_index, &idx); + + if (rar == NULL) { + WARN_ON(1); + return -EINVAL; + } + + low = rar->rar_addr[idx].low & 0xfffffc00u; + high = rar->rar_addr[idx].high & 0xfffffc00u; + + /* + * Only allow I/O from the graphics and Langwell; + * not from the x86 processor + */ + + if (rar_index == RAR_TYPE_VIDEO) { + low |= 0x00000009; + high |= 0x00000015; + } else if (rar_index == RAR_TYPE_AUDIO) { + /* Only allow I/O from Langwell; nothing from x86 */ + low |= 0x00000008; + high |= 0x00000018; + } else + /* Read-only from all agents */ + high |= 0x00000018; + + /* + * Now program the register using the Lincroft message + * bus interface. + */ + result = rar_set_addr(rar->rar_dev, + 2 * idx, low); + + if (result == 0) + result = rar_set_addr(rar->rar_dev, + 2 * idx + 1, high); + + return result; +} +EXPORT_SYMBOL(rar_lock); + +/** + * register_rar - register a RAR handler + * @num: RAR we wish to register for + * @callback: function to call when RAR support is available + * @data: data to pass to this function + * + * The register_rar function is to used by other device drivers + * to ensure that this driver is ready. As we cannot be sure of + * the compile/execute order of drivers in ther kernel, it is + * best to give this driver a callback function to call when + * it is ready to give out addresses. The callback function + * would have those steps that continue the initialization of + * a driver that do require a valid RAR address. One of those + * steps would be to call rar_get_address() + * + * This function return 0 on success or an error code on failure. + */ +int register_rar(int num, int (*callback)(unsigned long data), + unsigned long data) +{ + /* For now we hardcode a single RAR device */ + struct rar_device *rar; + struct client *c; + int idx; + int retval = 0; + + mutex_lock(&rar_mutex); + + /* Do we have a client mapping for this RAR number ? */ + c = rar_to_client(num); + if (c == NULL) { + retval = -ERANGE; + goto done; + } + /* Is it claimed ? */ + if (c->busy) { + retval = -EBUSY; + goto done; + } + c->busy = 1; + + /* See if we have a handler for this RAR yet, if we do then fire it */ + rar = rar_to_device(num, &idx); + + if (rar) { + /* + * if the driver already registered, then we can simply + * call the callback right now + */ + (*callback)(data); + goto done; + } + + /* Arrange to be called back when the hardware is found */ + c->callback = callback; + c->driver_priv = data; +done: + mutex_unlock(&rar_mutex); + return retval; +} +EXPORT_SYMBOL(register_rar); + +/** + * unregister_rar - release a RAR allocation + * @num: RAR number + * + * Releases a RAR allocation, or pending allocation. If a callback is + * pending then this function will either complete before the unregister + * returns or not at all. + */ + +void unregister_rar(int num) +{ + struct client *c; + + mutex_lock(&rar_mutex); + c = rar_to_client(num); + if (c == NULL || !c->busy) + WARN_ON(1); + else + c->busy = 0; + mutex_unlock(&rar_mutex); +} +EXPORT_SYMBOL(unregister_rar); + +/** + * rar_callback - Process callbacks + * @rar: new RAR device + * + * Process the callbacks for a newly found RAR device. + */ + +static void rar_callback(struct rar_device *rar) +{ + struct client *c = &rar->client[0]; + int i; + + mutex_lock(&rar_mutex); + + rar->registered = 1; /* Ensure no more callbacks queue */ + + for (i = 0; i < MRST_NUM_RAR; i++) { + if (c->callback && c->busy) { + c->callback(c->driver_priv); + c->callback = NULL; + } + c++; + } + mutex_unlock(&rar_mutex); +} + +/** + * rar_probe - PCI probe callback + * @dev: PCI device + * @id: matching entry in the match table + * + * A RAR device has been discovered. Initialise it and if successful + * process any pending callbacks that can now be completed. + */ +static int rar_probe(struct pci_dev *dev, const struct pci_device_id *id) +{ + int error; + struct rar_device *rar; + + dev_dbg(&dev->dev, "PCI probe starting\n"); + + rar = alloc_rar_device(); + if (rar == NULL) + return -EBUSY; + + /* Enable the device */ + error = pci_enable_device(dev); + if (error) { + dev_err(&dev->dev, + "Error enabling RAR register PCI device\n"); + goto end_function; + } + + /* Fill in the rar_device structure */ + rar->rar_dev = pci_dev_get(dev); + pci_set_drvdata(dev, rar); + + /* + * Initialize the RAR parameters, which have to be retrieved + * via the message bus interface. + */ + error = init_rar_params(rar); + if (error) { + pci_disable_device(dev); + dev_err(&dev->dev, "Error retrieving RAR addresses\n"); + goto end_function; + } + /* now call anyone who has registered (using callbacks) */ + rar_callback(rar); + return 0; +end_function: + free_rar_device(rar); + return error; +} + +const struct pci_device_id rar_pci_id_tbl[] = { + { PCI_VDEVICE(INTEL, 0x4110) }, + { 0 } +}; + +MODULE_DEVICE_TABLE(pci, rar_pci_id_tbl); + +const struct pci_device_id *my_id_table = rar_pci_id_tbl; + +/* field for registering driver to PCI device */ +static struct pci_driver rar_pci_driver = { + .name = "rar_register_driver", + .id_table = rar_pci_id_tbl, + .probe = rar_probe, + /* Cannot be unplugged - no remove */ +}; + +static int __init rar_init_handler(void) +{ + return pci_register_driver(&rar_pci_driver); +} + +static void __exit rar_exit_handler(void) +{ + pci_unregister_driver(&rar_pci_driver); +} + +module_init(rar_init_handler); +module_exit(rar_exit_handler); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Intel Restricted Access Region Register Driver"); diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig index 984a754..9dfef8a5 100644 --- a/drivers/staging/Kconfig +++ b/drivers/staging/Kconfig @@ -109,8 +109,6 @@ source "drivers/staging/hv/Kconfig" source "drivers/staging/vme/Kconfig" -source "drivers/staging/rar_register/Kconfig" - source "drivers/staging/memrar/Kconfig" source "drivers/staging/sep/Kconfig" diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile index 9fa2513..3dbf681 100644 --- a/drivers/staging/Makefile +++ b/drivers/staging/Makefile @@ -35,7 +35,6 @@ obj-$(CONFIG_VT6656) += vt6656/ obj-$(CONFIG_FB_UDL) += udlfb/ obj-$(CONFIG_HYPERV) += hv/ obj-$(CONFIG_VME_BUS) += vme/ -obj-$(CONFIG_RAR_REGISTER) += rar_register/ obj-$(CONFIG_MRST_RAR_HANDLER) += memrar/ obj-$(CONFIG_DX_SEP) += sep/ obj-$(CONFIG_IIO) += iio/ diff --git a/drivers/staging/memrar/memrar_handler.c b/drivers/staging/memrar/memrar_handler.c index efa7fd6..41876f2 100644 --- a/drivers/staging/memrar/memrar_handler.c +++ b/drivers/staging/memrar/memrar_handler.c @@ -47,8 +47,7 @@ #include #include #include - -#include "../rar_register/rar_register.h" +#include #include "memrar.h" #include "memrar_allocator.h" diff --git a/drivers/staging/rar_register/Kconfig b/drivers/staging/rar_register/Kconfig deleted file mode 100644 index e9c2773..0000000 --- a/drivers/staging/rar_register/Kconfig +++ /dev/null @@ -1,30 +0,0 @@ -# -# RAR device configuration -# - -menu "RAR Register Driver" -# -# Restricted Access Register Manager -# -config RAR_REGISTER - tristate "Restricted Access Region Register Driver" - depends on PCI - default n - ---help--- - This driver allows other kernel drivers access to the - contents of the restricted access region control registers. - - The restricted access region control registers - (rar_registers) are used to pass address and - locking information on restricted access regions - to other drivers that use restricted access regions. - - The restricted access regions are regions of memory - on the Intel MID Platform that are not accessible to - the x86 processor, but are accessible to dedicated - processors on board peripheral devices. - - The purpose of the restricted access regions is to - protect sensitive data from compromise by unauthorized - programs running on the x86 processor. -endmenu diff --git a/drivers/staging/rar_register/Makefile b/drivers/staging/rar_register/Makefile deleted file mode 100644 index d5954cc..0000000 --- a/drivers/staging/rar_register/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -EXTRA_CFLAGS += -DLITTLE__ENDIAN -obj-$(CONFIG_RAR_REGISTER) += rar_register.o diff --git a/drivers/staging/rar_register/rar_register.c b/drivers/staging/rar_register/rar_register.c deleted file mode 100644 index 618503f..0000000 --- a/drivers/staging/rar_register/rar_register.c +++ /dev/null @@ -1,675 +0,0 @@ -/* - * rar_register.c - An Intel Restricted Access Region register driver - * - * Copyright(c) 2009 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - * ------------------------------------------------------------------- - * 20091204 Mark Allyn - * Ossama Othman - * Cleanup per feedback from Alan Cox and Arjan Van De Ven - * - * 20090806 Ossama Othman - * Return zero high address if upper 22 bits is zero. - * Cleaned up checkpatch errors. - * Clarified that driver is dealing with bus addresses. - * - * 20090702 Ossama Othman - * Removed unnecessary include directives - * Cleaned up spinlocks. - * Cleaned up logging. - * Improved invalid parameter checks. - * Fixed and simplified RAR address retrieval and RAR locking - * code. - * - * 20090626 Mark Allyn - * Initial publish - */ - -#define DEBUG 1 - -#include "rar_register.h" - -#include -#include -#include -#include -#include - -/* === Lincroft Message Bus Interface === */ -#define LNC_MCR_OFFSET 0xD0 /* Message Control Register */ -#define LNC_MDR_OFFSET 0xD4 /* Message Data Register */ - -/* Message Opcodes */ -#define LNC_MESSAGE_READ_OPCODE 0xD0 -#define LNC_MESSAGE_WRITE_OPCODE 0xE0 - -/* Message Write Byte Enables */ -#define LNC_MESSAGE_BYTE_WRITE_ENABLES 0xF - -/* B-unit Port */ -#define LNC_BUNIT_PORT 0x3 - -/* === Lincroft B-Unit Registers - Programmed by IA32 firmware === */ -#define LNC_BRAR0L 0x10 -#define LNC_BRAR0H 0x11 -#define LNC_BRAR1L 0x12 -#define LNC_BRAR1H 0x13 -/* Reserved for SeP */ -#define LNC_BRAR2L 0x14 -#define LNC_BRAR2H 0x15 - -/* Moorestown supports three restricted access regions. */ -#define MRST_NUM_RAR 3 - -/* RAR Bus Address Range */ -struct rar_addr { - dma_addr_t low; - dma_addr_t high; -}; - -/* - * We create one of these for each RAR - */ -struct client { - int (*callback)(unsigned long data); - unsigned long driver_priv; - bool busy; -}; - -static DEFINE_MUTEX(rar_mutex); -static DEFINE_MUTEX(lnc_reg_mutex); - -/* - * One per RAR device (currently only one device) - */ -struct rar_device { - struct rar_addr rar_addr[MRST_NUM_RAR]; - struct pci_dev *rar_dev; - bool registered; - bool allocated; - struct client client[MRST_NUM_RAR]; -}; - -/* Current platforms have only one rar_device for 3 rar regions */ -static struct rar_device my_rar_device; - -/* - * Abstract out multiple device support. Current platforms only - * have a single RAR device. - */ - -/** - * alloc_rar_device - return a new RAR structure - * - * Return a new (but not yet ready) RAR device object - */ -static struct rar_device *alloc_rar_device(void) -{ - if (my_rar_device.allocated) - return NULL; - my_rar_device.allocated = 1; - return &my_rar_device; -} - -/** - * free_rar_device - free a RAR object - * @rar: the RAR device being freed - * - * Release a RAR object and any attached resources - */ -static void free_rar_device(struct rar_device *rar) -{ - pci_dev_put(rar->rar_dev); - rar->allocated = 0; -} - -/** - * _rar_to_device - return the device handling this RAR - * @rar: RAR number - * @off: returned offset - * - * Internal helper for looking up RAR devices. This and alloc are the - * two functions that need touching to go to multiple RAR devices. - */ -static struct rar_device *_rar_to_device(int rar, int *off) -{ - if (rar >= 0 && rar <= 3) { - *off = rar; - return &my_rar_device; - } - return NULL; -} - - -/** - * rar_to_device - return the device handling this RAR - * @rar: RAR number - * @off: returned offset - * - * Return the device this RAR maps to if one is present, otherwise - * returns NULL. Reports the offset relative to the base of this - * RAR device in off. - */ -static struct rar_device *rar_to_device(int rar, int *off) -{ - struct rar_device *rar_dev = _rar_to_device(rar, off); - if (rar_dev == NULL || !rar_dev->registered) - return NULL; - return rar_dev; -} - -/** - * rar_to_client - return the client handling this RAR - * @rar: RAR number - * - * Return the client this RAR maps to if a mapping is known, otherwise - * returns NULL. - */ -static struct client *rar_to_client(int rar) -{ - int idx; - struct rar_device *r = _rar_to_device(rar, &idx); - if (r != NULL) - return &r->client[idx]; - return NULL; -} - -/** - * rar_read_addr - retrieve a RAR mapping - * @pdev: PCI device for the RAR - * @offset: offset for message - * @addr: returned address - * - * Reads the address of a given RAR register. Returns 0 on success - * or an error code on failure. - */ -static int rar_read_addr(struct pci_dev *pdev, int offset, dma_addr_t *addr) -{ - /* - * ======== The Lincroft Message Bus Interface ======== - * Lincroft registers may be obtained via PCI from - * the host bridge using the Lincroft Message Bus - * Interface. That message bus interface is generally - * comprised of two registers: a control register (MCR, 0xDO) - * and a data register (MDR, 0xD4). - * - * The MCR (message control register) format is the following: - * 1. [31:24]: Opcode - * 2. [23:16]: Port - * 3. [15:8]: Register Offset - * 4. [7:4]: Byte Enables (use 0xF to set all of these bits - * to 1) - * 5. [3:0]: reserved - * - * Read (0xD0) and write (0xE0) opcodes are written to the - * control register when reading and writing to Lincroft - * registers, respectively. - * - * We're interested in registers found in the Lincroft - * B-unit. The B-unit port is 0x3. - * - * The six B-unit RAR register offsets we use are listed - * earlier in this file. - * - * Lastly writing to the MCR register requires the "Byte - * enables" bits to be set to 1. This may be achieved by - * writing 0xF at bit 4. - * - * The MDR (message data register) format is the following: - * 1. [31:0]: Read/Write Data - * - * Data being read from this register is only available after - * writing the appropriate control message to the MCR - * register. - * - * Data being written to this register must be written before - * writing the appropriate control message to the MCR - * register. - */ - - int result; - u32 addr32; - - /* Construct control message */ - u32 const message = - (LNC_MESSAGE_READ_OPCODE << 24) - | (LNC_BUNIT_PORT << 16) - | (offset << 8) - | (LNC_MESSAGE_BYTE_WRITE_ENABLES << 4); - - dev_dbg(&pdev->dev, "Offset for 'get' LNC MSG is %x\n", offset); - - /* - * We synchronize access to the Lincroft MCR and MDR registers - * until BOTH the command is issued through the MCR register - * and the corresponding data is read from the MDR register. - * Otherwise a race condition would exist between accesses to - * both registers. - */ - - mutex_lock(&lnc_reg_mutex); - - /* Send the control message */ - result = pci_write_config_dword(pdev, LNC_MCR_OFFSET, message); - if (!result) { - /* Read back the address as a 32bit value */ - result = pci_read_config_dword(pdev, LNC_MDR_OFFSET, &addr32); - *addr = (dma_addr_t)addr32; - } - mutex_unlock(&lnc_reg_mutex); - return result; -} - -/** - * rar_set_addr - Set a RAR mapping - * @pdev: PCI device for the RAR - * @offset: offset for message - * @addr: address to set - * - * Sets the address of a given RAR register. Returns 0 on success - * or an error code on failure. - */ -static int rar_set_addr(struct pci_dev *pdev, - int offset, - dma_addr_t addr) -{ - /* - * Data being written to this register must be written before - * writing the appropriate control message to the MCR - * register. - * See rar_get_addrs() for a description of the - * message bus interface being used here. - */ - - int result; - - /* Construct control message */ - u32 const message = (LNC_MESSAGE_WRITE_OPCODE << 24) - | (LNC_BUNIT_PORT << 16) - | (offset << 8) - | (LNC_MESSAGE_BYTE_WRITE_ENABLES << 4); - - /* - * We synchronize access to the Lincroft MCR and MDR registers - * until BOTH the command is issued through the MCR register - * and the corresponding data is read from the MDR register. - * Otherwise a race condition would exist between accesses to - * both registers. - */ - - mutex_lock(&lnc_reg_mutex); - - /* Send the control message */ - result = pci_write_config_dword(pdev, LNC_MDR_OFFSET, addr); - if (!result) - /* And address */ - result = pci_write_config_dword(pdev, LNC_MCR_OFFSET, message); - - mutex_unlock(&lnc_reg_mutex); - return result; -} - -/* - * rar_init_params - Initialize RAR parameters - * @rar: RAR device to initialise - * - * Initialize RAR parameters, such as bus addresses, etc. Returns 0 - * on success, or an error code on failure. - */ -static int init_rar_params(struct rar_device *rar) -{ - struct pci_dev *pdev = rar->rar_dev; - unsigned int i; - int result = 0; - int offset = 0x10; /* RAR 0 to 2 in order low/high/low/high/... */ - - /* Retrieve RAR start and end bus addresses. - * Access the RAR registers through the Lincroft Message Bus - * Interface on PCI device: 00:00.0 Host bridge. - */ - - for (i = 0; i < MRST_NUM_RAR; ++i) { - struct rar_addr *addr = &rar->rar_addr[i]; - - result = rar_read_addr(pdev, offset++, &addr->low); - if (result != 0) - return result; - - result = rar_read_addr(pdev, offset++, &addr->high); - if (result != 0) - return result; - - - /* - * Only the upper 22 bits of the RAR addresses are - * stored in their corresponding RAR registers so we - * must set the lower 10 bits accordingly. - - * The low address has its lower 10 bits cleared, and - * the high address has all its lower 10 bits set, - * e.g.: - * low = 0x2ffffc00 - */ - - addr->low &= (dma_addr_t)0xfffffc00u; - - /* - * Set bits 9:0 on uppser address if bits 31:10 are non - * zero; otherwize clear all bits - */ - - if ((addr->high & 0xfffffc00u) == 0) - addr->high = 0; - else - addr->high |= 0x3ffu; - } - /* Done accessing the device. */ - - if (result == 0) { - for (i = 0; i != MRST_NUM_RAR; ++i) { - /* - * "BRAR" refers to the RAR registers in the - * Lincroft B-unit. - */ - dev_info(&pdev->dev, "BRAR[%u] bus address range = " - "[%lx, %lx]\n", i, - (unsigned long)rar->rar_addr[i].low, - (unsigned long)rar->rar_addr[i].high); - } - } - return result; -} - -/** - * rar_get_address - get the bus address in a RAR - * @start: return value of start address of block - * @end: return value of end address of block - * - * The rar_get_address function is used by other device drivers - * to obtain RAR address information on a RAR. It takes three - * parameters: - * - * The function returns a 0 upon success or an error if there is no RAR - * facility on this system. - */ -int rar_get_address(int rar_index, dma_addr_t *start, dma_addr_t *end) -{ - int idx; - struct rar_device *rar = rar_to_device(rar_index, &idx); - - if (rar == NULL) { - WARN_ON(1); - return -ENODEV; - } - - *start = rar->rar_addr[idx].low; - *end = rar->rar_addr[idx].high; - return 0; -} -EXPORT_SYMBOL(rar_get_address); - -/** - * rar_lock - lock a RAR register - * @rar_index: RAR to lock (0-2) - * - * The rar_lock function is ued by other device drivers to lock an RAR. - * once a RAR is locked, it stays locked until the next system reboot. - * - * The function returns a 0 upon success or an error if there is no RAR - * facility on this system, or the locking fails - */ -int rar_lock(int rar_index) -{ - struct rar_device *rar; - int result; - int idx; - dma_addr_t low, high; - - rar = rar_to_device(rar_index, &idx); - - if (rar == NULL) { - WARN_ON(1); - return -EINVAL; - } - - low = rar->rar_addr[idx].low & 0xfffffc00u; - high = rar->rar_addr[idx].high & 0xfffffc00u; - - /* - * Only allow I/O from the graphics and Langwell; - * not from the x86 processor - */ - - if (rar_index == RAR_TYPE_VIDEO) { - low |= 0x00000009; - high |= 0x00000015; - } else if (rar_index == RAR_TYPE_AUDIO) { - /* Only allow I/O from Langwell; nothing from x86 */ - low |= 0x00000008; - high |= 0x00000018; - } else - /* Read-only from all agents */ - high |= 0x00000018; - - /* - * Now program the register using the Lincroft message - * bus interface. - */ - result = rar_set_addr(rar->rar_dev, - 2 * idx, low); - - if (result == 0) - result = rar_set_addr(rar->rar_dev, - 2 * idx + 1, high); - - return result; -} -EXPORT_SYMBOL(rar_lock); - -/** - * register_rar - register a RAR handler - * @num: RAR we wish to register for - * @callback: function to call when RAR support is available - * @data: data to pass to this function - * - * The register_rar function is to used by other device drivers - * to ensure that this driver is ready. As we cannot be sure of - * the compile/execute order of drivers in ther kernel, it is - * best to give this driver a callback function to call when - * it is ready to give out addresses. The callback function - * would have those steps that continue the initialization of - * a driver that do require a valid RAR address. One of those - * steps would be to call rar_get_address() - * - * This function return 0 on success an error code on failure. - */ -int register_rar(int num, int (*callback)(unsigned long data), - unsigned long data) -{ - /* For now we hardcode a single RAR device */ - struct rar_device *rar; - struct client *c; - int idx; - int retval = 0; - - mutex_lock(&rar_mutex); - - /* Do we have a client mapping for this RAR number ? */ - c = rar_to_client(num); - if (c == NULL) { - retval = -ERANGE; - goto done; - } - /* Is it claimed ? */ - if (c->busy) { - retval = -EBUSY; - goto done; - } - c->busy = 1; - - /* See if we have a handler for this RAR yet, if we do then fire it */ - rar = rar_to_device(num, &idx); - - if (rar) { - /* - * if the driver already registered, then we can simply - * call the callback right now - */ - (*callback)(data); - goto done; - } - - /* Arrange to be called back when the hardware is found */ - c->callback = callback; - c->driver_priv = data; -done: - mutex_unlock(&rar_mutex); - return retval; -} -EXPORT_SYMBOL(register_rar); - -/** - * unregister_rar - release a RAR allocation - * @num: RAR number - * - * Releases a RAR allocation, or pending allocation. If a callback is - * pending then this function will either complete before the unregister - * returns or not at all. - */ - -void unregister_rar(int num) -{ - struct client *c; - - mutex_lock(&rar_mutex); - c = rar_to_client(num); - if (c == NULL || !c->busy) - WARN_ON(1); - else - c->busy = 0; - mutex_unlock(&rar_mutex); -} -EXPORT_SYMBOL(unregister_rar); - -/** - * rar_callback - Process callbacks - * @rar: new RAR device - * - * Process the callbacks for a newly found RAR device. - */ - -static void rar_callback(struct rar_device *rar) -{ - struct client *c = &rar->client[0]; - int i; - - mutex_lock(&rar_mutex); - - rar->registered = 1; /* Ensure no more callbacks queue */ - - for (i = 0; i < MRST_NUM_RAR; i++) { - if (c->callback && c->busy) { - c->callback(c->driver_priv); - c->callback = NULL; - } - c++; - } - mutex_unlock(&rar_mutex); -} - -/** - * rar_probe - PCI probe callback - * @dev: PCI device - * @id: matching entry in the match table - * - * A RAR device has been discovered. Initialise it and if successful - * process any pending callbacks that can now be completed. - */ -static int rar_probe(struct pci_dev *dev, const struct pci_device_id *id) -{ - int error; - struct rar_device *rar; - - dev_dbg(&dev->dev, "PCI probe starting\n"); - - rar = alloc_rar_device(); - if (rar == NULL) - return -EBUSY; - - /* Enable the device */ - error = pci_enable_device(dev); - if (error) { - dev_err(&dev->dev, - "Error enabling RAR register PCI device\n"); - goto end_function; - } - - /* Fill in the rar_device structure */ - rar->rar_dev = pci_dev_get(dev); - pci_set_drvdata(dev, rar); - - /* - * Initialize the RAR parameters, which have to be retrieved - * via the message bus interface. - */ - error = init_rar_params(rar); - if (error) { - pci_disable_device(dev); - dev_err(&dev->dev, "Error retrieving RAR addresses\n"); - goto end_function; - } - /* now call anyone who has registered (using callbacks) */ - rar_callback(rar); - return 0; -end_function: - free_rar_device(rar); - return error; -} - -const struct pci_device_id rar_pci_id_tbl[] = { - { PCI_VDEVICE(INTEL, 0x4110) }, - { 0 } -}; - -MODULE_DEVICE_TABLE(pci, rar_pci_id_tbl); - -const struct pci_device_id *my_id_table = rar_pci_id_tbl; - -/* field for registering driver to PCI device */ -static struct pci_driver rar_pci_driver = { - .name = "rar_register_driver", - .id_table = rar_pci_id_tbl, - .probe = rar_probe, - /* Cannot be unplugged - no remove */ -}; - -static int __init rar_init_handler(void) -{ - return pci_register_driver(&rar_pci_driver); -} - -static void __exit rar_exit_handler(void) -{ - pci_unregister_driver(&rar_pci_driver); -} - -module_init(rar_init_handler); -module_exit(rar_exit_handler); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("Intel Restricted Access Region Register Driver"); diff --git a/drivers/staging/rar_register/rar_register.h b/drivers/staging/rar_register/rar_register.h deleted file mode 100644 index ffa8057..0000000 --- a/drivers/staging/rar_register/rar_register.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2010 Intel Corporation. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General - * Public License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * The full GNU General Public License is included in this - * distribution in the file called COPYING. - */ - - -#ifndef _RAR_REGISTER_H -#define _RAR_REGISTER_H - -#include - -/* following are used both in drivers as well as user space apps */ - -#define RAR_TYPE_VIDEO 0 -#define RAR_TYPE_AUDIO 1 -#define RAR_TYPE_IMAGE 2 -#define RAR_TYPE_DATA 3 - -#ifdef __KERNEL__ - -struct rar_device; - -int register_rar(int num, - int (*callback)(unsigned long data), unsigned long data); -void unregister_rar(int num); -int rar_get_address(int rar_index, dma_addr_t *start, dma_addr_t *end); -int rar_lock(int rar_index); - -#endif /* __KERNEL__ */ -#endif /* _RAR_REGISTER_H */ diff --git a/include/linux/rar_register.h b/include/linux/rar_register.h new file mode 100644 index 0000000..ffa8057 --- /dev/null +++ b/include/linux/rar_register.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2010 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General + * Public License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * The full GNU General Public License is included in this + * distribution in the file called COPYING. + */ + + +#ifndef _RAR_REGISTER_H +#define _RAR_REGISTER_H + +#include + +/* following are used both in drivers as well as user space apps */ + +#define RAR_TYPE_VIDEO 0 +#define RAR_TYPE_AUDIO 1 +#define RAR_TYPE_IMAGE 2 +#define RAR_TYPE_DATA 3 + +#ifdef __KERNEL__ + +struct rar_device; + +int register_rar(int num, + int (*callback)(unsigned long data), unsigned long data); +void unregister_rar(int num); +int rar_get_address(int rar_index, dma_addr_t *start, dma_addr_t *end); +int rar_lock(int rar_index); + +#endif /* __KERNEL__ */ +#endif /* _RAR_REGISTER_H */ -- cgit v0.10.2 From d5164dbf1f651d1e955b158fb70a9c844cc91cd1 Mon Sep 17 00:00:00 2001 From: Islam Amer Date: Thu, 24 Jun 2010 13:39:47 -0400 Subject: dell-wmi: Add support for eject key on Dell Studio 1555 Fixes pressing the eject key on Dell Studio 1555 does not work and produces message : dell-wmi: Unknown key 0 pressed Signed-off-by: Islam Amer diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c index 66f53c3..12a8e6f 100644 --- a/drivers/platform/x86/dell-wmi.c +++ b/drivers/platform/x86/dell-wmi.c @@ -221,7 +221,7 @@ static void dell_wmi_notify(u32 value, void *context) return; } - if (dell_new_hk_type) + if (dell_new_hk_type || buffer_entry[1] == 0x0) reported_key = (int)buffer_entry[2]; else reported_key = (int)buffer_entry[1] & 0xffff; -- cgit v0.10.2 From 1492616a434dae1908d0da2d6ee6605ca5a77e6f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 28 Jun 2010 09:30:45 +0800 Subject: wmi: fix a memory leak in wmi_notify_debug When acpi_evaluate_object() is passed ACPI_ALLOCATE_BUFFER, the caller must kfree the returned buffer if AE_OK is returned. The callers of wmi_get_event_data() pass ACPI_ALLOCATE_BUFFER, and thus must check its return value before accessing or kfree() on the buffer. This patch adds return value checking for wmi_get_event_data() and adds a missing kfree(obj) in the end of wmi_notify_debug Signed-off-by: Axel Lin Acked-by: Thomas Renninger Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 582b5cd..6c15720 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -518,8 +518,13 @@ static void wmi_notify_debug(u32 value, void *context) { struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; + acpi_status status; - wmi_get_event_data(value, &response); + status = wmi_get_event_data(value, &response); + if (status != AE_OK) { + printk(KERN_INFO "wmi: bad event status 0x%x\n", status); + return; + } obj = (union acpi_object *)response.pointer; @@ -543,6 +548,7 @@ static void wmi_notify_debug(u32 value, void *context) default: printk("object type 0x%X\n", obj->type); } + kfree(obj); } /** -- cgit v0.10.2 From d8eca1105fe2039e102c6a8a915d0af937b1b593 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 29 Jun 2010 11:09:47 +0800 Subject: asus-laptop: fix a memory leak in asus_laptop_get_info error path The callers of write_acpi_int_ret() pass ACPI_ALLOCATE_BUFFER, the caller must kfree the returned buffer if AE_OK is returned. This patch adds a missing kfree(buffer.pointer) before return -ENOMEM if kstrdup fail. Signed-off-by: Axel Lin Acked-by: Corentin Chary Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index efe8f63..4af5709 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -1397,8 +1397,10 @@ static int asus_laptop_get_info(struct asus_laptop *asus) } } asus->name = kstrdup(string, GFP_KERNEL); - if (!asus->name) + if (!asus->name) { + kfree(buffer.pointer); return -ENOMEM; + } if (*string) pr_notice(" %s model detected\n", string); -- cgit v0.10.2 From 370525df9dfb4f55dfc177b0c31c26d77694c992 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 30 Jun 2010 10:20:23 +0800 Subject: acer-wmi: set permissions on interface file to S_IRUGO The interface file is not writable, thus set permissions to S_IRUGO. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index 56e6f10..aacd060 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -1084,8 +1084,7 @@ static ssize_t show_interface(struct device *dev, struct device_attribute *attr, } } -static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR, - show_interface, NULL); +static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL); /* * debugfs functions -- cgit v0.10.2 From d53bf0f32410c8c738935aa3d9740d66d39ba967 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 30 Jun 2010 13:32:16 +0800 Subject: acer-wmi: make dmi_matched to return 1 instead of 0 dmi_check_system() walks the table running matching functions until someone returns non zero or we hit the end. This patch makes dmi_matched to return 1 so dmi_check_system() return immediately when a match is found. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index aacd060..dec558e 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -200,7 +200,7 @@ static void set_quirks(void) static int dmi_matched(const struct dmi_system_id *dmi) { quirks = dmi->driver_data; - return 0; + return 1; } static struct quirk_entry quirk_unknown = { -- cgit v0.10.2 From 32ab72e7ca7aed399b81a3ffec26d7353bd33581 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 30 Jun 2010 17:25:46 +0800 Subject: dell-wmi: fix a memory leak If dell_new_hk_type is true, dell_legacy_wmi_keymap will point to a memory allocated in setup_new_hk_map(). In this case, the memory is not freed in current implementation. This patch fixes the leak by kfree(dell_wmi_keymap) if dell_new_hk_type is true. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/dell-wmi.c b/drivers/platform/x86/dell-wmi.c index 12a8e6f..08fb70f 100644 --- a/drivers/platform/x86/dell-wmi.c +++ b/drivers/platform/x86/dell-wmi.c @@ -339,13 +339,18 @@ static int __init dell_wmi_init(void) acpi_video = acpi_video_backlight_support(); err = dell_wmi_input_setup(); - if (err) + if (err) { + if (dell_new_hk_type) + kfree(dell_wmi_keymap); return err; + } status = wmi_install_notify_handler(DELL_EVENT_GUID, dell_wmi_notify, NULL); if (ACPI_FAILURE(status)) { input_unregister_device(dell_wmi_input_dev); + if (dell_new_hk_type) + kfree(dell_wmi_keymap); printk(KERN_ERR "dell-wmi: Unable to register notify handler - %d\n", status); @@ -359,6 +364,8 @@ static void __exit dell_wmi_exit(void) { wmi_remove_notify_handler(DELL_EVENT_GUID); input_unregister_device(dell_wmi_input_dev); + if (dell_new_hk_type) + kfree(dell_wmi_keymap); } module_init(dell_wmi_init); -- cgit v0.10.2 From 08db2b3141b99b476749201eb8e164b39fa7a4ca Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 1 Jul 2010 10:18:01 +0800 Subject: sony-laptop: use platform_device_unregister in sony_pf_remove platform_device_unregister calls platform_device_del and platform_device_put, thus this change is logically equivalent to original code. I made this change because the documents in platform.c shows that: platform_device_del and platform_device_put must _only_ be externally called in error cases. All other usage is a bug. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c index a47fd4e..e3154ff 100644 --- a/drivers/platform/x86/sony-laptop.c +++ b/drivers/platform/x86/sony-laptop.c @@ -561,8 +561,7 @@ static void sony_pf_remove(void) if (!atomic_dec_and_test(&sony_pf_users)) return; - platform_device_del(sony_pf_device); - platform_device_put(sony_pf_device); + platform_device_unregister(sony_pf_device); platform_driver_unregister(&sony_pf_driver); } -- cgit v0.10.2 From ae42f234470662aefe65ab59a0ef228f1f6f9c77 Mon Sep 17 00:00:00 2001 From: Matthew Garrett Date: Thu, 15 Jul 2010 14:23:42 -0400 Subject: toshiba-acpi: Add an extra couple of keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thomas Bächler reports that his machine generates two keycodes for zooming in and out. Add these to the default keymap. Signed-off-by: Matthew Garrett Cc: Thomas Bächler diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 37aa147..a5e1aa3 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -129,6 +129,8 @@ enum {KE_KEY, KE_END}; static struct key_entry toshiba_acpi_keymap[] = { {KE_KEY, 0x101, KEY_MUTE}, + {KE_KEY, 0x102, KEY_ZOOMOUT}, + {KE_KEY, 0x103, KEY_ZOOMIN}, {KE_KEY, 0x13b, KEY_COFFEE}, {KE_KEY, 0x13c, KEY_BATTERY}, {KE_KEY, 0x13d, KEY_SLEEP}, -- cgit v0.10.2 From b096667bc3f01e2468df56d4a241dc5231b2f2aa Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Tue, 20 Jul 2010 15:19:29 -0700 Subject: hp-wmi: return -ENODEV if BIOS does not export any supported hp wmi guid Signed-off-by: Thomas Renninger Cc: Matthew Garrett Cc: Len Brown Cc: Axel Lin Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index d55bf58..34b4178 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -711,8 +711,10 @@ static int hp_wmi_resume_handler(struct device *device) static int __init hp_wmi_init(void) { int err; + int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); + int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); - if (wmi_has_guid(HPWMI_EVENT_GUID)) { + if (event_capable) { err = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL); if (ACPI_FAILURE(err)) @@ -724,7 +726,7 @@ static int __init hp_wmi_init(void) } } - if (wmi_has_guid(HPWMI_BIOS_GUID)) { + if (bios_capable) { err = platform_driver_register(&hp_wmi_driver); if (err) goto err_driver_reg; @@ -738,6 +740,9 @@ static int __init hp_wmi_init(void) goto err_device_add; } + if (!bios_capable && !event_capable) + return -ENODEV; + return 0; err_device_add: -- cgit v0.10.2 From 887b7ca9c55a5dd53413a467f7b02821ba7a6557 Mon Sep 17 00:00:00 2001 From: Peter Feuerer Date: Tue, 20 Jul 2010 15:19:30 -0700 Subject: acerhdf: add new BIOS versions Add new BIOS versions for Acer 1410 and 1810xx and Packard Bell netbooks. Fixed registers of Acer AOA150 BIOS version v0.3114: Old registers caused Fan to spin up at every temperature check. Signed-off-by: Peter Feuerer Cc: Borislav Petkov Cc: Andreas Mohr Cc: Len Brown Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 7b2384d..40be6a4 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -52,7 +52,7 @@ */ #undef START_IN_KERNEL_MODE -#define DRV_VER "0.5.22" +#define DRV_VER "0.5.23" /* * According to the Atom N270 datasheet, @@ -146,7 +146,7 @@ static const struct bios_settings_t bios_tbl[] = { {"Acer", "AOA110", "v0.3309", 0x55, 0x58, {0x21, 0x21, 0x00} }, {"Acer", "AOA110", "v0.3310", 0x55, 0x58, {0x21, 0x21, 0x00} }, /* AOA150 */ - {"Acer", "AOA150", "v0.3114", 0x55, 0x58, {0x20, 0x20, 0x00} }, + {"Acer", "AOA150", "v0.3114", 0x55, 0x58, {0x1f, 0x1f, 0x00} }, {"Acer", "AOA150", "v0.3301", 0x55, 0x58, {0x20, 0x20, 0x00} }, {"Acer", "AOA150", "v0.3304", 0x55, 0x58, {0x20, 0x20, 0x00} }, {"Acer", "AOA150", "v0.3305", 0x55, 0x58, {0x20, 0x20, 0x00} }, @@ -155,13 +155,20 @@ static const struct bios_settings_t bios_tbl[] = { {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x20, 0x00} }, {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x20, 0x00} }, /* Acer 1410 */ + {"Acer", "Aspire 1410", "v0.3115", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, {"Acer", "Aspire 1410", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, /* Acer 1810xx */ + {"Acer", "Aspire 1810TZ", "v0.3115", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3115", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v0.3119", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3119", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, {"Acer", "Aspire 1810TZ", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, {"Acer", "Aspire 1810T", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810T", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v1.3204", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v1.3204", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, {"Acer", "Aspire 1810TZ", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, /* Gateway */ {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x21, 0x00} }, {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x20, 0x00} }, @@ -175,6 +182,7 @@ static const struct bios_settings_t bios_tbl[] = { {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x20, 0x00} }, {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, /* pewpew-terminator */ {"", "", "", 0, 0, {0, 0, 0} } }; @@ -667,6 +675,7 @@ MODULE_ALIAS("dmi:*:*Gateway*:pnLT31*:"); MODULE_ALIAS("dmi:*:*Packard Bell*:pnAOA*:"); MODULE_ALIAS("dmi:*:*Packard Bell*:pnDOA*:"); MODULE_ALIAS("dmi:*:*Packard Bell*:pnDOTMU*:"); +MODULE_ALIAS("dmi:*:*Packard Bell*:pnDOTMA*:"); module_init(acerhdf_init); module_exit(acerhdf_exit); -- cgit v0.10.2 From 210183d4af87cc70d7e4552d325f238734cade15 Mon Sep 17 00:00:00 2001 From: Peter Feuerer Date: Tue, 20 Jul 2010 15:19:32 -0700 Subject: acerhdf: remove "chk_off" as it was only needed for T31 netbooks Remove "chk_off" as it was only needed for T31 netbooks. But those netbooks can also be handled just with "cmd_off" register (0x9e) for reading the state back. Signed-off-by: Peter Feuerer Cc: Borislav Petkov Cc: Andreas Mohr Cc: Len Brown Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 40be6a4..9226838 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -112,14 +112,12 @@ module_param_string(force_product, force_product, 16, 0); MODULE_PARM_DESC(force_product, "Force BIOS product and omit BIOS check"); /* - * cmd_off: to switch the fan completely off - * chk_off: to check if the fan is off + * cmd_off: to switch the fan completely off and check if the fan is off * cmd_auto: to set the BIOS in control of the fan. The BIOS regulates then * the fan speed depending on the temperature */ struct fancmd { u8 cmd_off; - u8 chk_off; u8 cmd_auto; }; @@ -136,55 +134,55 @@ struct bios_settings_t { /* Register addresses and values for different BIOS versions */ static const struct bios_settings_t bios_tbl[] = { /* AOA110 */ - {"Acer", "AOA110", "v0.3109", 0x55, 0x58, {0x1f, 0x1f, 0x00} }, - {"Acer", "AOA110", "v0.3114", 0x55, 0x58, {0x1f, 0x1f, 0x00} }, - {"Acer", "AOA110", "v0.3301", 0x55, 0x58, {0xaf, 0xaf, 0x00} }, - {"Acer", "AOA110", "v0.3304", 0x55, 0x58, {0xaf, 0xaf, 0x00} }, - {"Acer", "AOA110", "v0.3305", 0x55, 0x58, {0xaf, 0xaf, 0x00} }, - {"Acer", "AOA110", "v0.3307", 0x55, 0x58, {0xaf, 0xaf, 0x00} }, - {"Acer", "AOA110", "v0.3308", 0x55, 0x58, {0x21, 0x21, 0x00} }, - {"Acer", "AOA110", "v0.3309", 0x55, 0x58, {0x21, 0x21, 0x00} }, - {"Acer", "AOA110", "v0.3310", 0x55, 0x58, {0x21, 0x21, 0x00} }, + {"Acer", "AOA110", "v0.3109", 0x55, 0x58, {0x1f, 0x00} }, + {"Acer", "AOA110", "v0.3114", 0x55, 0x58, {0x1f, 0x00} }, + {"Acer", "AOA110", "v0.3301", 0x55, 0x58, {0xaf, 0x00} }, + {"Acer", "AOA110", "v0.3304", 0x55, 0x58, {0xaf, 0x00} }, + {"Acer", "AOA110", "v0.3305", 0x55, 0x58, {0xaf, 0x00} }, + {"Acer", "AOA110", "v0.3307", 0x55, 0x58, {0xaf, 0x00} }, + {"Acer", "AOA110", "v0.3308", 0x55, 0x58, {0x21, 0x00} }, + {"Acer", "AOA110", "v0.3309", 0x55, 0x58, {0x21, 0x00} }, + {"Acer", "AOA110", "v0.3310", 0x55, 0x58, {0x21, 0x00} }, /* AOA150 */ - {"Acer", "AOA150", "v0.3114", 0x55, 0x58, {0x1f, 0x1f, 0x00} }, - {"Acer", "AOA150", "v0.3301", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Acer", "AOA150", "v0.3304", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Acer", "AOA150", "v0.3305", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Acer", "AOA150", "v0.3307", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Acer", "AOA150", "v0.3308", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x20, 0x00} }, + {"Acer", "AOA150", "v0.3114", 0x55, 0x58, {0x1f, 0x00} }, + {"Acer", "AOA150", "v0.3301", 0x55, 0x58, {0x20, 0x00} }, + {"Acer", "AOA150", "v0.3304", 0x55, 0x58, {0x20, 0x00} }, + {"Acer", "AOA150", "v0.3305", 0x55, 0x58, {0x20, 0x00} }, + {"Acer", "AOA150", "v0.3307", 0x55, 0x58, {0x20, 0x00} }, + {"Acer", "AOA150", "v0.3308", 0x55, 0x58, {0x20, 0x00} }, + {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x00} }, + {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x00} }, /* Acer 1410 */ - {"Acer", "Aspire 1410", "v0.3115", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1410", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, /* Acer 1810xx */ - {"Acer", "Aspire 1810TZ", "v0.3115", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810T", "v0.3115", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810TZ", "v0.3119", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810T", "v0.3119", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810TZ", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810T", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810TZ", "v1.3204", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810T", "v1.3204", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810TZ", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Acer", "Aspire 1810T", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v0.3119", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3119", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v1.3204", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v1.3204", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, /* Gateway */ - {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x21, 0x00} }, - {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Gateway", "LT31", "v1.3103", 0x55, 0x58, {0x10, 0x0f, 0x00} }, - {"Gateway", "LT31", "v1.3201", 0x55, 0x58, {0x10, 0x0f, 0x00} }, - {"Gateway", "LT31", "v1.3302", 0x55, 0x58, {0x10, 0x0f, 0x00} }, + {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x00} }, + {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x00} }, + {"Gateway", "LT31", "v1.3103", 0x55, 0x58, {0x9e, 0x00} }, + {"Gateway", "LT31", "v1.3201", 0x55, 0x58, {0x9e, 0x00} }, + {"Gateway", "LT31", "v1.3302", 0x55, 0x58, {0x9e, 0x00} }, /* Packard Bell */ - {"Packard Bell", "DOA150", "v0.3104", 0x55, 0x58, {0x21, 0x21, 0x00} }, - {"Packard Bell", "DOA150", "v0.3105", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Packard Bell", "AOA110", "v0.3105", 0x55, 0x58, {0x21, 0x21, 0x00} }, - {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x20, 0x00} }, - {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, - {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x9e, 0x00} }, + {"Packard Bell", "DOA150", "v0.3104", 0x55, 0x58, {0x21, 0x00} }, + {"Packard Bell", "DOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00} }, + {"Packard Bell", "AOA110", "v0.3105", 0x55, 0x58, {0x21, 0x00} }, + {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00} }, + {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x00} }, /* pewpew-terminator */ - {"", "", "", 0, 0, {0, 0, 0} } + {"", "", "", 0, 0, {0, 0} } }; static const struct bios_settings_t *bios_cfg __read_mostly; @@ -208,7 +206,7 @@ static int acerhdf_get_fanstate(int *state) if (ec_read(bios_cfg->fanreg, &fan)) return -EINVAL; - if (fan != bios_cfg->cmd.chk_off) + if (fan != bios_cfg->cmd.cmd_off) *state = ACERHDF_FAN_AUTO; else *state = ACERHDF_FAN_OFF; -- cgit v0.10.2 From 5cf4c07a2805388b5645079039d9a8b4b9269e08 Mon Sep 17 00:00:00 2001 From: Rahul Chaturvedi Date: Tue, 20 Jul 2010 15:19:33 -0700 Subject: acerhdf: driver didn't verify the pointers in which it got product information Driver didn't verify the pointers in which it got product information back from DMI; on QEMU one of the pointers came back null, which made the driver crash and subsequently caused a kernel panic. Signed-off-by: Rahul Chaturvedi Signed-off-by: Peter Feuerer Cc: Borislav Petkov Cc: Andreas Mohr Cc: Len Brown Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 9226838..6abd3f1 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -524,6 +524,10 @@ static int acerhdf_check_hardware(void) version = dmi_get_system_info(DMI_BIOS_VERSION); product = dmi_get_system_info(DMI_PRODUCT_NAME); + if (!vendor || !version || !product) { + pr_err("error getting hardware information\n"); + return -EINVAL; + } pr_info("Acer Aspire One Fan driver, v.%s\n", DRV_VER); -- cgit v0.10.2 From 24964639e132375f3d7eee9354b565aaa824d1dd Mon Sep 17 00:00:00 2001 From: Peter Feuerer Date: Tue, 20 Jul 2010 15:19:33 -0700 Subject: acerhdf: add AO531 and many BIOS versions for 1410, 1810xx and packard bell netbooks Signed-off-by: Peter Feuerer Cc: Borislav Petkov Cc: Andreas Mohr Cc: Len Brown Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 6abd3f1..cfc0a5c 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -52,7 +52,7 @@ */ #undef START_IN_KERNEL_MODE -#define DRV_VER "0.5.23" +#define DRV_VER "0.5.24" /* * According to the Atom N270 datasheet, @@ -153,12 +153,25 @@ static const struct bios_settings_t bios_tbl[] = { {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x00} }, {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x00} }, /* Acer 1410 */ + {"Acer", "Aspire 1410", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v0.3113", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1410", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v0.3117", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v0.3119", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1410", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v1.3204", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v1.3308", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1410", "v1.3310", 0x55, 0x58, {0x9e, 0x00} }, /* Acer 1810xx */ + {"Acer", "Aspire 1810TZ", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v0.3113", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3113", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1810TZ", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1810T", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v0.3117", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v0.3117", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1810TZ", "v0.3119", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1810T", "v0.3119", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1810TZ", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, @@ -167,6 +180,12 @@ static const struct bios_settings_t bios_tbl[] = { {"Acer", "Aspire 1810T", "v1.3204", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1810TZ", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, {"Acer", "Aspire 1810T", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v1.3308", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v1.3308", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810TZ", "v1.3310", 0x55, 0x58, {0x9e, 0x00} }, + {"Acer", "Aspire 1810T", "v1.3310", 0x55, 0x58, {0x9e, 0x00} }, + /* Acer 531 */ + {"Acer", "AO531h", "v0.3201", 0x55, 0x58, {0x20, 0x00} }, /* Gateway */ {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x00} }, {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x00} }, @@ -180,7 +199,14 @@ static const struct bios_settings_t bios_tbl[] = { {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00} }, {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x00} }, {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMU", "v0.3108", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMU", "v0.3113", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMU", "v0.3115", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMU", "v0.3117", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMU", "v0.3119", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMU", "v1.3204", 0x55, 0x58, {0x9e, 0x00} }, {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x00} }, + {"Packard Bell", "DOTMA", "v1.3302", 0x55, 0x58, {0x9e, 0x00} }, /* pewpew-terminator */ {"", "", "", 0, 0, {0, 0} } }; @@ -672,6 +698,7 @@ MODULE_DESCRIPTION("Aspire One temperature and fan driver"); MODULE_ALIAS("dmi:*:*Acer*:pnAOA*:"); MODULE_ALIAS("dmi:*:*Acer*:pnAspire 1410*:"); MODULE_ALIAS("dmi:*:*Acer*:pnAspire 1810*:"); +MODULE_ALIAS("dmi:*:*Acer*:pnAO531*:"); MODULE_ALIAS("dmi:*:*Gateway*:pnAOA*:"); MODULE_ALIAS("dmi:*:*Gateway*:pnLT31*:"); MODULE_ALIAS("dmi:*:*Packard Bell*:pnAOA*:"); -- cgit v0.10.2 From 8e4e2efdfab5448b0a01be8883d62fc90cce2a7e Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:34 -0700 Subject: fujitsu-laptop: remove unnecessary input_free_device calls input_free_device() should only be used if input_register_device() was not called yet or if it failed. This patch removes unnecessary input_free_device calls. Signed-off-by: Axel Lin Acked-by: Jonathan Woithe Acked-by: Dmitry Torokhov Cc: Matthew Garrett a Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index e325aeb..4346d26 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -725,6 +725,7 @@ static int acpi_fujitsu_add(struct acpi_device *device) err_unregister_input_dev: input_unregister_device(input); + input = NULL; err_free_input_dev: input_free_device(input); err_stop: @@ -738,8 +739,6 @@ static int acpi_fujitsu_remove(struct acpi_device *device, int type) input_unregister_device(input); - input_free_device(input); - fujitsu->acpi_handle = NULL; return 0; @@ -930,6 +929,7 @@ static int acpi_fujitsu_hotkey_add(struct acpi_device *device) err_unregister_input_dev: input_unregister_device(input); + input = NULL; err_free_input_dev: input_free_device(input); err_free_fifo: @@ -953,8 +953,6 @@ static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type) input_unregister_device(input); - input_free_device(input); - kfifo_free(&fujitsu_hotkey->fifo); fujitsu_hotkey->acpi_handle = NULL; -- cgit v0.10.2 From c28341455c080356508cc375ba440018e150021c Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Tue, 20 Jul 2010 15:19:39 -0700 Subject: compal-laptop: uses hwmon interfaces, depends on HWMON compal-laptop uses hwmon interfaces, so it should depend on HWMON. compal-laptop.c:(.devinit.text+0x4071f): undefined reference to `hwmon_device_register' compal-laptop.c:(.devexit.text+0x6ec0): undefined reference to `hwmon_device_unregister' Signed-off-by: Randy Dunlap Cc: Roald Frederickx Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 2f173bc..2189565 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -182,6 +182,7 @@ config COMPAL_LAPTOP depends on ACPI depends on BACKLIGHT_CLASS_DEVICE depends on RFKILL + depends on HWMON ---help--- This is a driver for laptops built by Compal: -- cgit v0.10.2 From 9be0fcb5ed46509f859542fb2871ac2d277b5407 Mon Sep 17 00:00:00 2001 From: Roald Frederickx Date: Tue, 20 Jul 2010 15:19:39 -0700 Subject: compal-laptop: add JHL90, battery & hwmon interface The driver now supports the Compal JHL90 (which I use) and it has some added features. The biggest novelties are a battery interface (power_supply) and a temperature and fan control interface (hmwon). It also adds a power-off feature to the backlight subsystem and it exports a few files that can enable/disable wake_on_XXX events. Much of the original code of the old features is still there, but I've changed some names to keep the naming more coherent with the added functionalities. (Sorry for the huge patch) Some technical stuff about the new driver: First of all, I'm not sure if the extra features also work on the other Compal boards. Currently they only get enabled if the DMI data indicates you are on a JHL90 board. Secondly, I've noticed a quirk in my fan controller. I have to re-send the wanted pwm-level to the controller every so often. If I don't do this, the fanspeed will slowly rise until after a couple of minutes it's at full speed. (Note that every normal userland application will probably update the pwm-level every so often anyway, based on temperature readings, so this might not be an issue in practice) If this turns out to be a problem with all the controllers, maybe we should implement a kernel timer and have the driver re-send the pwm level every XX seconds to make this transparent to userspace? (However, I couldn't immediately find a way to do this cleanly.) Additional information can be found in the source comments. [akpm@linux-foundation.org: coding-style fixes] [akpm@linux-foundation.org: add missing semicolon] Signed-off-by: Roald Frederickx Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c index 71ff154..0dbc0bb 100644 --- a/drivers/platform/x86/compal-laptop.c +++ b/drivers/platform/x86/compal-laptop.c @@ -24,17 +24,50 @@ */ /* - * comapl-laptop.c - Compal laptop support. + * compal-laptop.c - Compal laptop support. + * + * This driver exports a few files in /sys/devices/platform/compal-laptop/: + * wake_up_XXX Whether or not we listen to such wake up events (rw) + * + * In addition to these platform device attributes the driver + * registers itself in the Linux backlight control, power_supply, rfkill + * and hwmon subsystem and is available to userspace under: + * + * /sys/class/backlight/compal-laptop/ + * /sys/class/power_supply/compal-laptop/ + * /sys/class/rfkill/rfkillX/ + * /sys/class/hwmon/hwmonX/ + * + * Notes on the power_supply battery interface: + * - the "minimum" design voltage is *the* design voltage + * - the ambient temperature is the average battery temperature + * and the value is an educated guess (see commented code below) * - * The driver registers itself with the rfkill subsystem and - * the Linux backlight control subsystem. * * This driver might work on other laptops produced by Compal. If you * want to try it you can pass force=1 as argument to the module which * will force it to load even when the DMI data doesn't identify the - * laptop as FL9x. + * laptop as compatible. + * + * Lots of data available at: + * http://service1.marasst.com/Compal/JHL90_91/Service%20Manual/ + * JHL90%20service%20manual-Final-0725.pdf + * + * + * + * Support for the Compal JHL90 added by Roald Frederickx + * (roald.frederickx@gmail.com): + * Driver got large revision. Added functionalities: backlight + * power, wake_on_XXX, a hwmon and power_supply interface. + * + * In case this gets merged into the kernel source: I want to dedicate this + * to Kasper Meerts, the awesome guy who showed me Linux and C! */ +/* NOTE: currently the wake_on_XXX, hwmon and power_supply interfaces are + * only enabled on a JHL90 board until it is verified that they work on the + * other boards too. See the extra_features variable. */ + #include #include #include @@ -43,71 +76,296 @@ #include #include #include +#include +#include +#include +#include + + +/* ======= */ +/* Defines */ +/* ======= */ +#define DRIVER_NAME "compal-laptop" +#define DRIVER_VERSION "0.2.7" + +#define BACKLIGHT_LEVEL_ADDR 0xB9 +#define BACKLIGHT_LEVEL_MAX 7 +#define BACKLIGHT_STATE_ADDR 0x59 +#define BACKLIGHT_STATE_ON_DATA 0xE1 +#define BACKLIGHT_STATE_OFF_DATA 0xE2 + +#define WAKE_UP_ADDR 0xA4 +#define WAKE_UP_PME (1 << 0) +#define WAKE_UP_MODEM (1 << 1) +#define WAKE_UP_LAN (1 << 2) +#define WAKE_UP_WLAN (1 << 4) +#define WAKE_UP_KEY (1 << 6) +#define WAKE_UP_MOUSE (1 << 7) + +#define WIRELESS_ADDR 0xBB +#define WIRELESS_WLAN (1 << 0) +#define WIRELESS_BT (1 << 1) +#define WIRELESS_WLAN_EXISTS (1 << 2) +#define WIRELESS_BT_EXISTS (1 << 3) +#define WIRELESS_KILLSWITCH (1 << 4) + +#define PWM_ADDRESS 0x46 +#define PWM_DISABLE_ADDR 0x59 +#define PWM_DISABLE_DATA 0xA5 +#define PWM_ENABLE_ADDR 0x59 +#define PWM_ENABLE_DATA 0xA8 + +#define FAN_ADDRESS 0x46 +#define FAN_DATA 0x81 +#define FAN_FULL_ON_CMD 0x59 /* Doesn't seem to work. Just */ +#define FAN_FULL_ON_ENABLE 0x76 /* force the pwm signal to its */ +#define FAN_FULL_ON_DISABLE 0x77 /* maximum value instead */ + +#define TEMP_CPU 0xB0 +#define TEMP_CPU_LOCAL 0xB1 +#define TEMP_CPU_DTS 0xB5 +#define TEMP_NORTHBRIDGE 0xB6 +#define TEMP_VGA 0xB4 +#define TEMP_SKIN 0xB2 + +#define BAT_MANUFACTURER_NAME_ADDR 0x10 +#define BAT_MANUFACTURER_NAME_LEN 9 +#define BAT_MODEL_NAME_ADDR 0x19 +#define BAT_MODEL_NAME_LEN 6 +#define BAT_SERIAL_NUMBER_ADDR 0xC4 +#define BAT_SERIAL_NUMBER_LEN 5 +#define BAT_CHARGE_NOW 0xC2 +#define BAT_CHARGE_DESIGN 0xCA +#define BAT_VOLTAGE_NOW 0xC6 +#define BAT_VOLTAGE_DESIGN 0xC8 +#define BAT_CURRENT_NOW 0xD0 +#define BAT_CURRENT_AVG 0xD2 +#define BAT_POWER 0xD4 +#define BAT_CAPACITY 0xCE +#define BAT_TEMP 0xD6 +#define BAT_TEMP_AVG 0xD7 +#define BAT_STATUS0 0xC1 +#define BAT_STATUS1 0xF0 +#define BAT_STATUS2 0xF1 +#define BAT_STOP_CHARGE1 0xF2 +#define BAT_STOP_CHARGE2 0xF3 + +#define BAT_S0_DISCHARGE (1 << 0) +#define BAT_S0_DISCHRG_CRITICAL (1 << 2) +#define BAT_S0_LOW (1 << 3) +#define BAT_S0_CHARGING (1 << 1) +#define BAT_S0_AC (1 << 7) +#define BAT_S1_EXISTS (1 << 0) +#define BAT_S1_FULL (1 << 1) +#define BAT_S1_EMPTY (1 << 2) +#define BAT_S1_LiION_OR_NiMH (1 << 7) +#define BAT_S2_LOW_LOW (1 << 0) +#define BAT_STOP_CHRG1_BAD_CELL (1 << 1) +#define BAT_STOP_CHRG1_COMM_FAIL (1 << 2) +#define BAT_STOP_CHRG1_OVERVOLTAGE (1 << 6) +#define BAT_STOP_CHRG1_OVERTEMPERATURE (1 << 7) + + +/* ======= */ +/* Structs */ +/* ======= */ +struct compal_data{ + /* Fan control */ + struct device *hwmon_dev; + int pwm_enable; /* 0:full on, 1:set by pwm1, 2:control by moterboard */ + unsigned char curr_pwm; + + /* Power supply */ + struct power_supply psy; + struct power_supply_info psy_info; + char bat_model_name[BAT_MODEL_NAME_LEN + 1]; + char bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN + 1]; + char bat_serial_number[BAT_SERIAL_NUMBER_LEN + 1]; +}; -#define COMPAL_DRIVER_VERSION "0.2.6" -#define COMPAL_LCD_LEVEL_MAX 8 +/* =============== */ +/* General globals */ +/* =============== */ +static int force; +module_param(force, bool, 0); +MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); -#define COMPAL_EC_COMMAND_WIRELESS 0xBB -#define COMPAL_EC_COMMAND_LCD_LEVEL 0xB9 +/* Support for the wake_on_XXX, hwmon and power_supply interface. Currently + * only gets enabled on a JHL90 board. Might work with the others too */ +static bool extra_features; + +/* Nasty stuff. For some reason the fan control is very un-linear. I've + * come up with these values by looping through the possible inputs and + * watching the output of address 0x4F (do an ec_transaction writing 0x33 + * into 0x4F and read a few bytes from the output, like so: + * u8 writeData = 0x33; + * ec_transaction(0x4F, &writeData, 1, buffer, 32, 0); + * That address is labled "fan1 table information" in the service manual. + * It should be clear which value in 'buffer' changes). This seems to be + * related to fan speed. It isn't a proper 'realtime' fan speed value + * though, because physically stopping or speeding up the fan doesn't + * change it. It might be the average voltage or current of the pwm output. + * Nevertheless, it is more fine-grained than the actual RPM reading */ +static const unsigned char pwm_lookup_table[256] = { + 0, 0, 0, 1, 1, 1, 2, 253, 254, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, + 7, 7, 7, 8, 86, 86, 9, 9, 9, 10, 10, 10, 11, 92, 92, 12, 12, 95, + 13, 66, 66, 14, 14, 98, 15, 15, 15, 16, 16, 67, 17, 17, 72, 18, 70, + 75, 19, 90, 90, 73, 73, 73, 21, 21, 91, 91, 91, 96, 23, 94, 94, 94, + 94, 94, 94, 94, 94, 94, 94, 141, 141, 238, 223, 192, 139, 139, 139, + 139, 139, 142, 142, 142, 142, 142, 78, 78, 78, 78, 78, 76, 76, 76, + 76, 76, 79, 79, 79, 79, 79, 79, 79, 20, 20, 20, 20, 20, 22, 22, 22, + 22, 22, 24, 24, 24, 24, 24, 24, 219, 219, 219, 219, 219, 219, 219, + 219, 27, 27, 188, 188, 28, 28, 28, 29, 186, 186, 186, 186, 186, + 186, 186, 186, 186, 186, 31, 31, 31, 31, 31, 32, 32, 32, 41, 33, + 33, 33, 33, 33, 252, 252, 34, 34, 34, 43, 35, 35, 35, 36, 36, 38, + 206, 206, 206, 206, 206, 206, 206, 206, 206, 37, 37, 37, 46, 46, + 47, 47, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 48, 48, + 48, 48, 48, 40, 40, 40, 49, 42, 42, 42, 42, 42, 42, 42, 42, 44, + 189, 189, 189, 189, 54, 54, 45, 45, 45, 45, 45, 45, 45, 45, 251, + 191, 199, 199, 199, 199, 199, 215, 215, 215, 215, 187, 187, 187, + 187, 187, 193, 50 +}; -#define KILLSWITCH_MASK 0x10 -#define WLAN_MASK 0x01 -#define BT_MASK 0x02 -static struct rfkill *wifi_rfkill; -static struct rfkill *bt_rfkill; -static struct platform_device *compal_device; -static int force; -module_param(force, bool, 0); -MODULE_PARM_DESC(force, "Force driver load, ignore DMI data"); -/* Hardware access */ +/* ========================= */ +/* Hardware access functions */ +/* ========================= */ +/* General access */ +static u8 ec_read_u8(u8 addr) +{ + u8 value; + ec_read(addr, &value); + return value; +} + +static s8 ec_read_s8(u8 addr) +{ + return (s8)ec_read_u8(addr); +} + +static u16 ec_read_u16(u8 addr) +{ + int hi, lo; + lo = ec_read_u8(addr); + hi = ec_read_u8(addr + 1); + return (hi << 8) + lo; +} + +static s16 ec_read_s16(u8 addr) +{ + return (s16) ec_read_u16(addr); +} -static int set_lcd_level(int level) +static void ec_read_sequence(u8 addr, u8 *buf, int len) { - if (level < 0 || level >= COMPAL_LCD_LEVEL_MAX) + int i; + for (i = 0; i < len; i++) + ec_read(addr + i, buf + i); +} + + +/* Backlight access */ +static int set_backlight_level(int level) +{ + if (level < 0 || level > BACKLIGHT_LEVEL_MAX) return -EINVAL; - ec_write(COMPAL_EC_COMMAND_LCD_LEVEL, level); + ec_write(BACKLIGHT_LEVEL_ADDR, level); return 0; } -static int get_lcd_level(void) +static int get_backlight_level(void) +{ + return (int) ec_read_u8(BACKLIGHT_LEVEL_ADDR); +} + +static void set_backlight_state(bool on) +{ + u8 data = on ? BACKLIGHT_STATE_ON_DATA : BACKLIGHT_STATE_OFF_DATA; + ec_transaction(BACKLIGHT_STATE_ADDR, &data, 1, NULL, 0, 0); +} + + +/* Fan control access */ +static void pwm_enable_control(void) +{ + unsigned char writeData = PWM_ENABLE_DATA; + ec_transaction(PWM_ENABLE_ADDR, &writeData, 1, NULL, 0, 0); +} + +static void pwm_disable_control(void) { - u8 result; + unsigned char writeData = PWM_DISABLE_DATA; + ec_transaction(PWM_DISABLE_ADDR, &writeData, 1, NULL, 0, 0); +} - ec_read(COMPAL_EC_COMMAND_LCD_LEVEL, &result); +static void set_pwm(int pwm) +{ + ec_transaction(PWM_ADDRESS, &pwm_lookup_table[pwm], 1, NULL, 0, 0); +} + +static int get_fan_rpm(void) +{ + u8 value, data = FAN_DATA; + ec_transaction(FAN_ADDRESS, &data, 1, &value, 1, 0); + return 100 * (int)value; +} + + + + +/* =================== */ +/* Interface functions */ +/* =================== */ + +/* Backlight interface */ +static int bl_get_brightness(struct backlight_device *b) +{ + return get_backlight_level(); +} + +static int bl_update_status(struct backlight_device *b) +{ + int ret = set_backlight_level(b->props.brightness); + if (ret) + return ret; - return (int) result; + set_backlight_state((b->props.power == FB_BLANK_UNBLANK) + && !(b->props.state & BL_CORE_SUSPENDED) + && !(b->props.state & BL_CORE_FBBLANK)); + return 0; } +static const struct backlight_ops compalbl_ops = { + .get_brightness = bl_get_brightness, + .update_status = bl_update_status, +}; + + +/* Wireless interface */ static int compal_rfkill_set(void *data, bool blocked) { unsigned long radio = (unsigned long) data; - u8 result, value; - - ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); + u8 result = ec_read_u8(WIRELESS_ADDR); + u8 value; if (!blocked) value = (u8) (result | radio); else value = (u8) (result & ~radio); - ec_write(COMPAL_EC_COMMAND_WIRELESS, value); + ec_write(WIRELESS_ADDR, value); return 0; } static void compal_rfkill_poll(struct rfkill *rfkill, void *data) { - u8 result; - bool hw_blocked; - - ec_read(COMPAL_EC_COMMAND_WIRELESS, &result); - - hw_blocked = !(result & KILLSWITCH_MASK); + u8 result = ec_read_u8(WIRELESS_ADDR); + bool hw_blocked = !(result & WIRELESS_KILLSWITCH); rfkill_set_hw_state(rfkill, hw_blocked); } @@ -116,80 +374,404 @@ static const struct rfkill_ops compal_rfkill_ops = { .set_block = compal_rfkill_set, }; -static int setup_rfkill(void) + +/* Wake_up interface */ +#define SIMPLE_MASKED_STORE_SHOW(NAME, ADDR, MASK) \ +static ssize_t NAME##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + return sprintf(buf, "%d\n", ((ec_read_u8(ADDR) & MASK) != 0)); \ +} \ +static ssize_t NAME##_store(struct device *dev, \ + struct device_attribute *attr, const char *buf, size_t count) \ +{ \ + int state; \ + u8 old_val = ec_read_u8(ADDR); \ + if (sscanf(buf, "%d", &state) != 1 || (state < 0 || state > 1)) \ + return -EINVAL; \ + ec_write(ADDR, state ? (old_val | MASK) : (old_val & ~MASK)); \ + return count; \ +} + +SIMPLE_MASKED_STORE_SHOW(wake_up_pme, WAKE_UP_ADDR, WAKE_UP_PME) +SIMPLE_MASKED_STORE_SHOW(wake_up_modem, WAKE_UP_ADDR, WAKE_UP_MODEM) +SIMPLE_MASKED_STORE_SHOW(wake_up_lan, WAKE_UP_ADDR, WAKE_UP_LAN) +SIMPLE_MASKED_STORE_SHOW(wake_up_wlan, WAKE_UP_ADDR, WAKE_UP_WLAN) +SIMPLE_MASKED_STORE_SHOW(wake_up_key, WAKE_UP_ADDR, WAKE_UP_KEY) +SIMPLE_MASKED_STORE_SHOW(wake_up_mouse, WAKE_UP_ADDR, WAKE_UP_MOUSE) + + +/* General hwmon interface */ +static ssize_t hwmon_name_show(struct device *dev, + struct device_attribute *attr, char *buf) { - int ret; + return sprintf(buf, "%s\n", DRIVER_NAME); +} - wifi_rfkill = rfkill_alloc("compal-wifi", &compal_device->dev, - RFKILL_TYPE_WLAN, &compal_rfkill_ops, - (void *) WLAN_MASK); - if (!wifi_rfkill) - return -ENOMEM; - ret = rfkill_register(wifi_rfkill); - if (ret) - goto err_wifi; +/* Fan control interface */ +static ssize_t pwm_enable_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct compal_data *data = dev_get_drvdata(dev); + return sprintf(buf, "%d\n", data->pwm_enable); +} - bt_rfkill = rfkill_alloc("compal-bluetooth", &compal_device->dev, - RFKILL_TYPE_BLUETOOTH, &compal_rfkill_ops, - (void *) BT_MASK); - if (!bt_rfkill) { - ret = -ENOMEM; - goto err_allocate_bt; +static ssize_t pwm_enable_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + struct compal_data *data = dev_get_drvdata(dev); + long val; + int err; + err = strict_strtol(buf, 10, &val); + if (err) + return err; + if (val < 0) + return -EINVAL; + + data->pwm_enable = val; + + switch (val) { + case 0: /* Full speed */ + pwm_enable_control(); + set_pwm(255); + break; + case 1: /* As set by pwm1 */ + pwm_enable_control(); + set_pwm(data->curr_pwm); + break; + default: /* Control by motherboard */ + pwm_disable_control(); + break; } - ret = rfkill_register(bt_rfkill); - if (ret) - goto err_register_bt; - return 0; + return count; +} -err_register_bt: - rfkill_destroy(bt_rfkill); +static ssize_t pwm_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct compal_data *data = dev_get_drvdata(dev); + return sprintf(buf, "%hhu\n", data->curr_pwm); +} -err_allocate_bt: - rfkill_unregister(wifi_rfkill); +static ssize_t pwm_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct compal_data *data = dev_get_drvdata(dev); + long val; + int err; + err = strict_strtol(buf, 10, &val); + if (err) + return err; + if (val < 0 || val > 255) + return -EINVAL; -err_wifi: - rfkill_destroy(wifi_rfkill); + data->curr_pwm = val; - return ret; + if (data->pwm_enable != 1) + return count; + set_pwm(val); + + return count; } -/* Backlight device stuff */ +static ssize_t fan_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "%d\n", get_fan_rpm()); +} -static int bl_get_brightness(struct backlight_device *b) + +/* Temperature interface */ +#define TEMPERATURE_SHOW_TEMP_AND_LABEL(POSTFIX, ADDRESS, LABEL) \ +static ssize_t temp_##POSTFIX(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + return sprintf(buf, "%d\n", 1000 * (int)ec_read_s8(ADDRESS)); \ +} \ +static ssize_t label_##POSTFIX(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + return sprintf(buf, "%s\n", LABEL); \ +} + +/* Labels as in service guide */ +TEMPERATURE_SHOW_TEMP_AND_LABEL(cpu, TEMP_CPU, "CPU_TEMP"); +TEMPERATURE_SHOW_TEMP_AND_LABEL(cpu_local, TEMP_CPU_LOCAL, "CPU_TEMP_LOCAL"); +TEMPERATURE_SHOW_TEMP_AND_LABEL(cpu_DTS, TEMP_CPU_DTS, "CPU_DTS"); +TEMPERATURE_SHOW_TEMP_AND_LABEL(northbridge,TEMP_NORTHBRIDGE,"NorthBridge"); +TEMPERATURE_SHOW_TEMP_AND_LABEL(vga, TEMP_VGA, "VGA_TEMP"); +TEMPERATURE_SHOW_TEMP_AND_LABEL(SKIN, TEMP_SKIN, "SKIN_TEMP90"); + + +/* Power supply interface */ +static int bat_status(void) { - return get_lcd_level(); + u8 status0 = ec_read_u8(BAT_STATUS0); + u8 status1 = ec_read_u8(BAT_STATUS1); + + if (status0 & BAT_S0_CHARGING) + return POWER_SUPPLY_STATUS_CHARGING; + if (status0 & BAT_S0_DISCHARGE) + return POWER_SUPPLY_STATUS_DISCHARGING; + if (status1 & BAT_S1_FULL) + return POWER_SUPPLY_STATUS_FULL; + return POWER_SUPPLY_STATUS_NOT_CHARGING; } +static int bat_health(void) +{ + u8 status = ec_read_u8(BAT_STOP_CHARGE1); + + if (status & BAT_STOP_CHRG1_OVERTEMPERATURE) + return POWER_SUPPLY_HEALTH_OVERHEAT; + if (status & BAT_STOP_CHRG1_OVERVOLTAGE) + return POWER_SUPPLY_HEALTH_OVERVOLTAGE; + if (status & BAT_STOP_CHRG1_BAD_CELL) + return POWER_SUPPLY_HEALTH_DEAD; + if (status & BAT_STOP_CHRG1_COMM_FAIL) + return POWER_SUPPLY_HEALTH_UNKNOWN; + return POWER_SUPPLY_HEALTH_GOOD; +} -static int bl_update_status(struct backlight_device *b) +static int bat_is_present(void) { - return set_lcd_level(b->props.brightness); + u8 status = ec_read_u8(BAT_STATUS2); + return ((status & BAT_S1_EXISTS) != 0); +} + +static int bat_technology(void) +{ + u8 status = ec_read_u8(BAT_STATUS1); + + if (status & BAT_S1_LiION_OR_NiMH) + return POWER_SUPPLY_TECHNOLOGY_LION; + return POWER_SUPPLY_TECHNOLOGY_NiMH; +} + +static int bat_capacity_level(void) +{ + u8 status0 = ec_read_u8(BAT_STATUS0); + u8 status1 = ec_read_u8(BAT_STATUS1); + u8 status2 = ec_read_u8(BAT_STATUS2); + + if (status0 & BAT_S0_DISCHRG_CRITICAL + || status1 & BAT_S1_EMPTY + || status2 & BAT_S2_LOW_LOW) + return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; + if (status0 & BAT_S0_LOW) + return POWER_SUPPLY_CAPACITY_LEVEL_LOW; + if (status1 & BAT_S1_FULL) + return POWER_SUPPLY_CAPACITY_LEVEL_FULL; + return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; +} + +static int bat_get_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct compal_data *data; + data = container_of(psy, struct compal_data, psy); + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + val->intval = bat_status(); + break; + case POWER_SUPPLY_PROP_HEALTH: + val->intval = bat_health(); + break; + case POWER_SUPPLY_PROP_PRESENT: + val->intval = bat_is_present(); + break; + case POWER_SUPPLY_PROP_TECHNOLOGY: + val->intval = bat_technology(); + break; + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: /* THE design voltage... */ + val->intval = ec_read_u16(BAT_VOLTAGE_DESIGN) * 1000; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + val->intval = ec_read_u16(BAT_VOLTAGE_NOW) * 1000; + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + val->intval = ec_read_s16(BAT_CURRENT_NOW) * 1000; + break; + case POWER_SUPPLY_PROP_CURRENT_AVG: + val->intval = ec_read_s16(BAT_CURRENT_AVG) * 1000; + break; + case POWER_SUPPLY_PROP_POWER_NOW: + val->intval = ec_read_u8(BAT_POWER) * 1000000; + break; + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval = ec_read_u16(BAT_CHARGE_DESIGN) * 1000; + break; + case POWER_SUPPLY_PROP_CHARGE_NOW: + val->intval = ec_read_u16(BAT_CHARGE_NOW) * 1000; + break; + case POWER_SUPPLY_PROP_CAPACITY: + val->intval = ec_read_u8(BAT_CAPACITY); + break; + case POWER_SUPPLY_PROP_CAPACITY_LEVEL: + val->intval = bat_capacity_level(); + break; + /* It smees that BAT_TEMP_AVG is a (2's complement?) value showing + * the number of degrees, whereas BAT_TEMP is somewhat more + * complicated. It looks like this is a negative nember with a + * 100/256 divider and an offset of 222. Both were determined + * experimentally by comparing BAT_TEMP and BAT_TEMP_AVG. */ + case POWER_SUPPLY_PROP_TEMP: + val->intval = ((222 - (int)ec_read_u8(BAT_TEMP)) * 1000) >> 8; + break; + case POWER_SUPPLY_PROP_TEMP_AMBIENT: /* Ambient, Avg, ... same thing */ + val->intval = ec_read_s8(BAT_TEMP_AVG) * 10; + break; + /* Neither the model name nor manufacturer name work for me. */ + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = data->bat_model_name; + break; + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval = data->bat_manufacturer_name; + break; + case POWER_SUPPLY_PROP_SERIAL_NUMBER: + val->strval = data->bat_serial_number; + break; + default: + break; + } + return 0; } -static struct backlight_ops compalbl_ops = { - .get_brightness = bl_get_brightness, - .update_status = bl_update_status, -}; -static struct backlight_device *compalbl_device; + +/* ============== */ +/* Driver Globals */ +/* ============== */ +static DEVICE_ATTR(wake_up_pme, + 0644, wake_up_pme_show, wake_up_pme_store); +static DEVICE_ATTR(wake_up_modem, + 0644, wake_up_modem_show, wake_up_modem_store); +static DEVICE_ATTR(wake_up_lan, + 0644, wake_up_lan_show, wake_up_lan_store); +static DEVICE_ATTR(wake_up_wlan, + 0644, wake_up_wlan_show, wake_up_wlan_store); +static DEVICE_ATTR(wake_up_key, + 0644, wake_up_key_show, wake_up_key_store); +static DEVICE_ATTR(wake_up_mouse, + 0644, wake_up_mouse_show, wake_up_mouse_store); + +static SENSOR_DEVICE_ATTR(name, S_IRUGO, hwmon_name_show, NULL, 1); +static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, fan_show, NULL, 1); +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, temp_cpu, NULL, 1); +static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, temp_cpu_local, NULL, 1); +static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, temp_cpu_DTS, NULL, 1); +static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, temp_northbridge, NULL, 1); +static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, temp_vga, NULL, 1); +static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, temp_SKIN, NULL, 1); +static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, label_cpu, NULL, 1); +static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, label_cpu_local, NULL, 1); +static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, label_cpu_DTS, NULL, 1); +static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, label_northbridge, NULL, 1); +static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO, label_vga, NULL, 1); +static SENSOR_DEVICE_ATTR(temp6_label, S_IRUGO, label_SKIN, NULL, 1); +static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, pwm_show, pwm_store, 1); +static SENSOR_DEVICE_ATTR(pwm1_enable, + S_IRUGO | S_IWUSR, pwm_enable_show, pwm_enable_store, 0); + +static struct attribute *compal_attributes[] = { + &dev_attr_wake_up_pme.attr, + &dev_attr_wake_up_modem.attr, + &dev_attr_wake_up_lan.attr, + &dev_attr_wake_up_wlan.attr, + &dev_attr_wake_up_key.attr, + &dev_attr_wake_up_mouse.attr, + /* Maybe put the sensor-stuff in a separate hwmon-driver? That way, + * the hwmon sysfs won't be cluttered with the above files. */ + &sensor_dev_attr_name.dev_attr.attr, + &sensor_dev_attr_pwm1_enable.dev_attr.attr, + &sensor_dev_attr_pwm1.dev_attr.attr, + &sensor_dev_attr_fan1_input.dev_attr.attr, + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_temp2_input.dev_attr.attr, + &sensor_dev_attr_temp3_input.dev_attr.attr, + &sensor_dev_attr_temp4_input.dev_attr.attr, + &sensor_dev_attr_temp5_input.dev_attr.attr, + &sensor_dev_attr_temp6_input.dev_attr.attr, + &sensor_dev_attr_temp1_label.dev_attr.attr, + &sensor_dev_attr_temp2_label.dev_attr.attr, + &sensor_dev_attr_temp3_label.dev_attr.attr, + &sensor_dev_attr_temp4_label.dev_attr.attr, + &sensor_dev_attr_temp5_label.dev_attr.attr, + &sensor_dev_attr_temp6_label.dev_attr.attr, + NULL +}; + +static struct attribute_group compal_attribute_group = { + .attrs = compal_attributes +}; + +static int __devinit compal_probe(struct platform_device *); +static int __devexit compal_remove(struct platform_device *); static struct platform_driver compal_driver = { .driver = { - .name = "compal-laptop", + .name = DRIVER_NAME, .owner = THIS_MODULE, - } + }, + .probe = compal_probe, + .remove = __devexit_p(compal_remove) +}; + +static enum power_supply_property compal_bat_properties[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_TECHNOLOGY, + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CURRENT_AVG, + POWER_SUPPLY_PROP_POWER_NOW, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_CAPACITY_LEVEL, + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_TEMP_AMBIENT, + POWER_SUPPLY_PROP_MODEL_NAME, + POWER_SUPPLY_PROP_MANUFACTURER, + POWER_SUPPLY_PROP_SERIAL_NUMBER, }; -/* Initialization */ +static struct backlight_device *compalbl_device; + +static struct platform_device *compal_device; + +static struct rfkill *wifi_rfkill; +static struct rfkill *bt_rfkill; + + + + + +/* =================================== */ +/* Initialization & clean-up functions */ +/* =================================== */ static int dmi_check_cb(const struct dmi_system_id *id) { - printk(KERN_INFO "compal-laptop: Identified laptop model '%s'.\n", + printk(KERN_INFO DRIVER_NAME": Identified laptop model '%s'\n", id->ident); + extra_features = false; + return 0; +} +static int dmi_check_cb_extra(const struct dmi_system_id *id) +{ + printk(KERN_INFO DRIVER_NAME": Identified laptop model '%s', " + "enabling extra features\n", + id->ident); + extra_features = true; return 0; } @@ -274,27 +856,106 @@ static struct dmi_system_id __initdata compal_dmi_table[] = { }, .callback = dmi_check_cb }, - + { + .ident = "JHL90", + .matches = { + DMI_MATCH(DMI_BOARD_NAME, "JHL90"), + DMI_MATCH(DMI_BOARD_VERSION, "REFERENCE"), + }, + .callback = dmi_check_cb_extra + }, { } }; +static void initialize_power_supply_data(struct compal_data *data) +{ + data->psy.name = DRIVER_NAME; + data->psy.type = POWER_SUPPLY_TYPE_BATTERY; + data->psy.properties = compal_bat_properties; + data->psy.num_properties = ARRAY_SIZE(compal_bat_properties); + data->psy.get_property = bat_get_property; + + ec_read_sequence(BAT_MANUFACTURER_NAME_ADDR, + data->bat_manufacturer_name, + BAT_MANUFACTURER_NAME_LEN); + data->bat_manufacturer_name[BAT_MANUFACTURER_NAME_LEN] = 0; + + ec_read_sequence(BAT_MODEL_NAME_ADDR, + data->bat_model_name, + BAT_MODEL_NAME_LEN); + data->bat_model_name[BAT_MODEL_NAME_LEN] = 0; + + scnprintf(data->bat_serial_number, BAT_SERIAL_NUMBER_LEN + 1, "%d", + ec_read_u16(BAT_SERIAL_NUMBER_ADDR)); +} + +static void initialize_fan_control_data(struct compal_data *data) +{ + data->pwm_enable = 2; /* Keep motherboard in control for now */ + data->curr_pwm = 255; /* Try not to cause a CPU_on_fire exception + if we take over... */ +} + +static int setup_rfkill(void) +{ + int ret; + + wifi_rfkill = rfkill_alloc("compal-wifi", &compal_device->dev, + RFKILL_TYPE_WLAN, &compal_rfkill_ops, + (void *) WIRELESS_WLAN); + if (!wifi_rfkill) + return -ENOMEM; + + ret = rfkill_register(wifi_rfkill); + if (ret) + goto err_wifi; + + bt_rfkill = rfkill_alloc("compal-bluetooth", &compal_device->dev, + RFKILL_TYPE_BLUETOOTH, &compal_rfkill_ops, + (void *) WIRELESS_BT); + if (!bt_rfkill) { + ret = -ENOMEM; + goto err_allocate_bt; + } + ret = rfkill_register(bt_rfkill); + if (ret) + goto err_register_bt; + + return 0; + +err_register_bt: + rfkill_destroy(bt_rfkill); + +err_allocate_bt: + rfkill_unregister(wifi_rfkill); + +err_wifi: + rfkill_destroy(wifi_rfkill); + + return ret; +} + static int __init compal_init(void) { int ret; - if (acpi_disabled) + if (acpi_disabled) { + printk(KERN_ERR DRIVER_NAME": ACPI needs to be enabled for " + "this driver to work!\n"); return -ENODEV; + } - if (!force && !dmi_check_system(compal_dmi_table)) + if (!force && !dmi_check_system(compal_dmi_table)) { + printk(KERN_ERR DRIVER_NAME": Motherboard not recognized (You " + "could try the module's force-parameter)"); return -ENODEV; - - /* Register backlight stuff */ + } if (!acpi_video_backlight_support()) { struct backlight_properties props; memset(&props, 0, sizeof(struct backlight_properties)); - props.max_brightness = COMPAL_LCD_LEVEL_MAX - 1; - compalbl_device = backlight_device_register("compal-laptop", + props.max_brightness = BACKLIGHT_LEVEL_MAX; + compalbl_device = backlight_device_register(DRIVER_NAME, NULL, NULL, &compalbl_ops, &props); @@ -304,67 +965,122 @@ static int __init compal_init(void) ret = platform_driver_register(&compal_driver); if (ret) - goto fail_backlight; - - /* Register platform stuff */ + goto err_backlight; - compal_device = platform_device_alloc("compal-laptop", -1); + compal_device = platform_device_alloc(DRIVER_NAME, -1); if (!compal_device) { ret = -ENOMEM; - goto fail_platform_driver; + goto err_platform_driver; } - ret = platform_device_add(compal_device); + ret = platform_device_add(compal_device); /* This calls compal_probe */ if (ret) - goto fail_platform_device; + goto err_platform_device; ret = setup_rfkill(); if (ret) - goto fail_rfkill; - - printk(KERN_INFO "compal-laptop: driver "COMPAL_DRIVER_VERSION - " successfully loaded.\n"); + goto err_rfkill; + printk(KERN_INFO DRIVER_NAME": Driver "DRIVER_VERSION + " successfully loaded\n"); return 0; -fail_rfkill: +err_rfkill: platform_device_del(compal_device); -fail_platform_device: - +err_platform_device: platform_device_put(compal_device); -fail_platform_driver: - +err_platform_driver: platform_driver_unregister(&compal_driver); -fail_backlight: - +err_backlight: backlight_device_unregister(compalbl_device); return ret; } -static void __exit compal_cleanup(void) +static int __devinit compal_probe(struct platform_device *pdev) { + int err; + struct compal_data *data; + + if (!extra_features) + return 0; + + /* Fan control */ + data = kzalloc(sizeof(struct compal_data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + initialize_fan_control_data(data); + + err = sysfs_create_group(&pdev->dev.kobj, &compal_attribute_group); + if (err) + return err; + + data->hwmon_dev = hwmon_device_register(&pdev->dev); + if (IS_ERR(data->hwmon_dev)) { + err = PTR_ERR(data->hwmon_dev); + sysfs_remove_group(&pdev->dev.kobj, + &compal_attribute_group); + kfree(data); + return err; + } + + /* Power supply */ + initialize_power_supply_data(data); + power_supply_register(&compal_device->dev, &data->psy); + + platform_set_drvdata(pdev, data); + + return 0; +} +static void __exit compal_cleanup(void) +{ platform_device_unregister(compal_device); platform_driver_unregister(&compal_driver); backlight_device_unregister(compalbl_device); rfkill_unregister(wifi_rfkill); - rfkill_destroy(wifi_rfkill); rfkill_unregister(bt_rfkill); + rfkill_destroy(wifi_rfkill); rfkill_destroy(bt_rfkill); - printk(KERN_INFO "compal-laptop: driver unloaded.\n"); + printk(KERN_INFO DRIVER_NAME": Driver unloaded\n"); } +static int __devexit compal_remove(struct platform_device *pdev) +{ + struct compal_data *data; + + if (!extra_features) + return 0; + + printk(KERN_INFO DRIVER_NAME": Unloading: resetting fan control " + "to motherboard\n"); + pwm_disable_control(); + + data = platform_get_drvdata(pdev); + hwmon_device_unregister(data->hwmon_dev); + power_supply_unregister(&data->psy); + + platform_set_drvdata(pdev, NULL); + kfree(data); + + sysfs_remove_group(&pdev->dev.kobj, &compal_attribute_group); + + return 0; +} + + module_init(compal_init); module_exit(compal_cleanup); MODULE_AUTHOR("Cezary Jackiewicz"); +MODULE_AUTHOR("Roald Frederickx (roald.frederickx@gmail.com)"); MODULE_DESCRIPTION("Compal Laptop Support"); -MODULE_VERSION(COMPAL_DRIVER_VERSION); +MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL"); MODULE_ALIAS("dmi:*:rnIFL90:rvrIFT00:*"); @@ -372,6 +1088,7 @@ MODULE_ALIAS("dmi:*:rnIFL90:rvrREFERENCE:*"); MODULE_ALIAS("dmi:*:rnIFL91:rvrIFT00:*"); MODULE_ALIAS("dmi:*:rnJFL92:rvrIFT00:*"); MODULE_ALIAS("dmi:*:rnIFT00:rvrIFT00:*"); +MODULE_ALIAS("dmi:*:rnJHL90:rvrREFERENCE:*"); MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron910:*"); MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1010:*"); MODULE_ALIAS("dmi:*:svnDellInc.:pnInspiron1011:*"); -- cgit v0.10.2 From 80183a4b637982d56965e4a27b823c9a29d185b3 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:40 -0700 Subject: compal-laptop/fujitsu-laptop/msi-laptop: make dmi_check_cb to return 1 instead of 0 dmi_check_system() walks the table running matching functions until someone returns non zero or we hit the end. This patch makes dmi_check_cb to return 1 so dmi_check_system() return immediately when a match is found. Signed-off-by: Axel Lin Acked-by: Jonathan Woithe Cc: Matthew Garrett a Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c index 0dbc0bb..d071ce0 100644 --- a/drivers/platform/x86/compal-laptop.c +++ b/drivers/platform/x86/compal-laptop.c @@ -275,7 +275,7 @@ static int set_backlight_level(int level) ec_write(BACKLIGHT_LEVEL_ADDR, level); - return 0; + return 1; } static int get_backlight_level(void) diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index 4346d26..daf95f1 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -603,7 +603,7 @@ static int dmi_check_cb_s6410(const struct dmi_system_id *id) dmi_check_cb_common(id); fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ - return 0; + return 1; } static int dmi_check_cb_s6420(const struct dmi_system_id *id) @@ -611,7 +611,7 @@ static int dmi_check_cb_s6420(const struct dmi_system_id *id) dmi_check_cb_common(id); fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */ fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */ - return 0; + return 1; } static int dmi_check_cb_p8010(const struct dmi_system_id *id) @@ -620,7 +620,7 @@ static int dmi_check_cb_p8010(const struct dmi_system_id *id) fujitsu->keycode1 = KEY_HELP; /* "Support" */ fujitsu->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */ fujitsu->keycode4 = KEY_WWW; /* "Internet" */ - return 0; + return 1; } static struct dmi_system_id fujitsu_dmi_table[] = { diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c index afd762b..c67a74c 100644 --- a/drivers/platform/x86/msi-laptop.c +++ b/drivers/platform/x86/msi-laptop.c @@ -434,7 +434,7 @@ static int dmi_check_cb(const struct dmi_system_id *id) { printk(KERN_INFO "msi-laptop: Identified laptop model '%s'.\n", id->ident); - return 0; + return 1; } static struct dmi_system_id __initdata msi_dmi_table[] = { -- cgit v0.10.2 From d47bb5b227f103f9bc0e572f478ac6b2a08fc2b2 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:41 -0700 Subject: asus_acpi: fix a memory leak in asus_hotk_get_info() In the case of no match ( hotk->model == END_MODEL ), model sholud be kfreed before return AE_OK. This patch includes below fixes: 1. adds a missing kfree(model) before return AE_OK. 2. asus_hotk_get_info should return int, thus return 0 instead of AE_OK. Signed-off-by: Axel Lin Cc: Corentin Chary Cc: Karol Kozimor Cc: Matthew Garrett Cc: Len Brown Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c index 92fd30c..ae0914d 100644 --- a/drivers/platform/x86/asus_acpi.c +++ b/drivers/platform/x86/asus_acpi.c @@ -1340,7 +1340,8 @@ static int asus_hotk_get_info(void) return -ENODEV; } hotk->methods = &model_conf[hotk->model]; - return AE_OK; + kfree(model); + return 0; } hotk->methods = &model_conf[hotk->model]; printk(KERN_NOTICE " %s model detected, supported\n", string); @@ -1374,7 +1375,7 @@ static int asus_hotk_get_info(void) kfree(model); - return AE_OK; + return 0; } static int asus_hotk_check(void) -- cgit v0.10.2 From 3bf460f7b2767df63b76257332c4a9a29d5733c1 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:42 -0700 Subject: asus_acpi: fix coding style to improve readability In the case of no match ( hotk->model == END_MODEL ), the only posible case to return 0 is to have a Samsung P30 detected. This patch improves readability by moving related code after if/else clause to be inside if clause. Signed-off-by: Axel Lin Cc: Corentin Chary Cc: Karol Kozimor Cc: Matthew Garrett Cc: Len Brown Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c index ae0914d..e058c2b 100644 --- a/drivers/platform/x86/asus_acpi.c +++ b/drivers/platform/x86/asus_acpi.c @@ -1330,6 +1330,9 @@ static int asus_hotk_get_info(void) hotk->model = P30; printk(KERN_NOTICE " Samsung P30 detected, supported\n"); + hotk->methods = &model_conf[hotk->model]; + kfree(model); + return 0; } else { hotk->model = M2E; printk(KERN_NOTICE " unsupported model %s, trying " @@ -1339,9 +1342,6 @@ static int asus_hotk_get_info(void) kfree(model); return -ENODEV; } - hotk->methods = &model_conf[hotk->model]; - kfree(model); - return 0; } hotk->methods = &model_conf[hotk->model]; printk(KERN_NOTICE " %s model detected, supported\n", string); -- cgit v0.10.2 From fedae5ad61fc213eda78d4905316eb50e35b6c8f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:43 -0700 Subject: acerhdf: make needlessly global symbols static The following symbols are needlessly defined global: thz_dev cl_dev acerhdf_dev acerhdf_dev_ops acerhdf_cooling_ops This patch makes the symbols static. Signed-off-by: Axel Lin Acked-by: Borislav Petkov Acked-by: Peter Feuerer Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index cfc0a5c..4ce28d9 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -92,9 +92,9 @@ static unsigned int fanstate = ACERHDF_FAN_AUTO; static char force_bios[16]; static char force_product[16]; static unsigned int prev_interval; -struct thermal_zone_device *thz_dev; -struct thermal_cooling_device *cl_dev; -struct platform_device *acerhdf_dev; +static struct thermal_zone_device *thz_dev; +static struct thermal_cooling_device *cl_dev; +static struct platform_device *acerhdf_dev; module_param(kernelmode, uint, 0); MODULE_PARM_DESC(kernelmode, "Kernel mode fan control on / off"); @@ -406,7 +406,7 @@ static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal, } /* bind callback functions to thermalzone */ -struct thermal_zone_device_ops acerhdf_dev_ops = { +static struct thermal_zone_device_ops acerhdf_dev_ops = { .bind = acerhdf_bind, .unbind = acerhdf_unbind, .get_temp = acerhdf_get_ec_temp, @@ -481,7 +481,7 @@ err_out: } /* bind fan callbacks to fan device */ -struct thermal_cooling_device_ops acerhdf_cooling_ops = { +static struct thermal_cooling_device_ops acerhdf_cooling_ops = { .get_max_state = acerhdf_get_max_state, .get_cur_state = acerhdf_get_cur_state, .set_cur_state = acerhdf_set_cur_state, -- cgit v0.10.2 From df92754dddc77003c6be9540ff91bf89fcfce890 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:44 -0700 Subject: classmate-laptop: make needlessly global symbols static cmpc_accel_sensitivity_attr is needlessly defined global. This patch makes the symbol static. Signed-off-by: Axel Lin Acked-by: Thadeu Lima de Souza Cascardo Cc: Daniel Oliveira Nascimento Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c index 73ea76e..341cbfe 100644 --- a/drivers/platform/x86/classmate-laptop.c +++ b/drivers/platform/x86/classmate-laptop.c @@ -208,7 +208,7 @@ static ssize_t cmpc_accel_sensitivity_store(struct device *dev, return strnlen(buf, count); } -struct device_attribute cmpc_accel_sensitivity_attr = { +static struct device_attribute cmpc_accel_sensitivity_attr = { .attr = { .name = "sensitivity", .mode = 0660 }, .show = cmpc_accel_sensitivity_show, .store = cmpc_accel_sensitivity_store -- cgit v0.10.2 From 67af7111689b0b615d27b1a5fcc553bee4639831 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:45 -0700 Subject: fujitsu-laptop: make needlessly global symbols static The following symbols are needlessly defined global: logolamp_led kblamps_led This patch makes the symbols static. Signed-off-by: Axel Lin Cc: Matthew Garrett Acked-by: Jonathan Woithe Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c index daf95f1..f44cd26 100644 --- a/drivers/platform/x86/fujitsu-laptop.c +++ b/drivers/platform/x86/fujitsu-laptop.c @@ -182,7 +182,7 @@ static enum led_brightness logolamp_get(struct led_classdev *cdev); static void logolamp_set(struct led_classdev *cdev, enum led_brightness brightness); -struct led_classdev logolamp_led = { +static struct led_classdev logolamp_led = { .name = "fujitsu::logolamp", .brightness_get = logolamp_get, .brightness_set = logolamp_set @@ -192,7 +192,7 @@ static enum led_brightness kblamps_get(struct led_classdev *cdev); static void kblamps_set(struct led_classdev *cdev, enum led_brightness brightness); -struct led_classdev kblamps_led = { +static struct led_classdev kblamps_led = { .name = "fujitsu::kblamps", .brightness_get = kblamps_get, .brightness_set = kblamps_set -- cgit v0.10.2 From e38f052ba5fd4d3d8eb547e7d0c6bc1143a2babd Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:46 -0700 Subject: msi-laptop: make struct rfkill_ops const rfkill uses a const struct rfkill_ops pointer. Signed-off-by: Axel Lin Cc: Matthew Garrett Cc: Lennart Poettering Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c index c67a74c..7e9bb6d 100644 --- a/drivers/platform/x86/msi-laptop.c +++ b/drivers/platform/x86/msi-laptop.c @@ -562,15 +562,15 @@ static int rfkill_threeg_set(void *data, bool blocked) return 0; } -static struct rfkill_ops rfkill_bluetooth_ops = { +static const struct rfkill_ops rfkill_bluetooth_ops = { .set_block = rfkill_bluetooth_set }; -static struct rfkill_ops rfkill_wlan_ops = { +static const struct rfkill_ops rfkill_wlan_ops = { .set_block = rfkill_wlan_set }; -static struct rfkill_ops rfkill_threeg_ops = { +static const struct rfkill_ops rfkill_threeg_ops = { .set_block = rfkill_threeg_set }; -- cgit v0.10.2 From 9fb866f317def195bb794120e13d1d73c2a94bb2 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:47 -0700 Subject: asus-laptop: fix incorrect return value for write_acpi_int_ret if handle is NULL According to the comments of write_acpi_int_ret(), write_acpi_int_ret() should return 0 if write is successful, -1 else. Thus if handle is NULL, the write does not happen, it should return -1. Signed-off-by: Axel Lin Cc: Matthew Garrett Cc: Corentin Chary Cc: Alan Jenkins Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index 4af5709..19445ea 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -297,7 +297,7 @@ static int write_acpi_int_ret(acpi_handle handle, const char *method, int val, acpi_status status; if (!handle) - return 0; + return -1; params.count = 1; params.pointer = &in_obj; -- cgit v0.10.2 From 6a984a06487129f013ee2df6ce98b6cfada1e7b1 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:48 -0700 Subject: asus-laptop: return proper error for store_ledd if write_acpi_int fail In current implementation, store_ledd() does not return error if write_acpi_int fail. This patch fixes it by return -ENODEV if write_acpi_int fail. Signed-off-by: Axel Lin Cc: Matthew Garrett Cc: Corentin Chary Cc: Alan Jenkins Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index 19445ea..40897ba 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -796,10 +796,11 @@ static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, rv = parse_arg(buf, count, &value); if (rv > 0) { - if (write_acpi_int(asus->handle, METHOD_LEDD, value)) + if (write_acpi_int(asus->handle, METHOD_LEDD, value)) { pr_warning("LED display write failed\n"); - else - asus->ledd_status = (u32) value; + return -ENODEV; + } + asus->ledd_status = (u32) value; } return rv; } -- cgit v0.10.2 From a0dba697eec78fb2d4e2b76b83104a2b251ae70d Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:49 -0700 Subject: acerhdf: fix resource reclaim in error path Fix resource reclaim in below cases: 1. acerhdf_register_platform() does not properly handle platform_device_alloc() failure and platform_device_add() failure This patch adds error handing for acerhdf_register_platform(). 2. acerhdf_register_platform() return err with acerhdf_dev == NULL. as a result, acerhdf_unregister_platform() does not do resource reclaim in acerhdf_init() error path. This patch adds error handing for acerhdf_register_platform(), thus correct the error handing path in acerhdf_init(). goto out_err instead of err_unreg if acerhdf_register_platform() fail. 3. platform_device_del() should only used in error handling. Current implementation missed a platform_device_put() in acerhdf_exit. This patch fixes it by using platform_device_unregister() instead of platform_device_del() in acerhdf_unregister_platform. Signed-off-by: Axel Lin Acked-by: Peter Feuerer Cc: Matthew Garrett Acked-by: Borislav Petkov Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acerhdf.c b/drivers/platform/x86/acerhdf.c index 4ce28d9..60f9cfc 100644 --- a/drivers/platform/x86/acerhdf.c +++ b/drivers/platform/x86/acerhdf.c @@ -615,17 +615,26 @@ static int acerhdf_register_platform(void) return err; acerhdf_dev = platform_device_alloc("acerhdf", -1); - platform_device_add(acerhdf_dev); + if (!acerhdf_dev) { + err = -ENOMEM; + goto err_device_alloc; + } + err = platform_device_add(acerhdf_dev); + if (err) + goto err_device_add; return 0; + +err_device_add: + platform_device_put(acerhdf_dev); +err_device_alloc: + platform_driver_unregister(&acerhdf_driver); + return err; } static void acerhdf_unregister_platform(void) { - if (!acerhdf_dev) - return; - - platform_device_del(acerhdf_dev); + platform_device_unregister(acerhdf_dev); platform_driver_unregister(&acerhdf_driver); } @@ -669,7 +678,7 @@ static int __init acerhdf_init(void) err = acerhdf_register_platform(); if (err) - goto err_unreg; + goto out_err; err = acerhdf_register_thermal(); if (err) @@ -682,7 +691,7 @@ err_unreg: acerhdf_unregister_platform(); out_err: - return -ENODEV; + return err; } static void __exit acerhdf_exit(void) -- cgit v0.10.2 From 1bd1ca1f4ce99c5be041bfc2997e394cdb5240dc Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:50 -0700 Subject: toshiba_acpi: make remove_device() and add_device() void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit remove_device() and add_device() are not related to ACPI APIs, it does not make sense to return acpi_status for both functions. Current implementation of add_device() always AE_OK, thus the return value checking for add_device() always return false for ACPI_FAILURE(status). This patch makes add_device() to be void and remove the unnecessary return value checking. remove_proc_entry() won't fail, thus change remove_device() to be void. Signed-off-by: Axel Lin Cc: Matthew Garrett Cc: Márton Németh Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index a5e1aa3..c8bb7eb 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -722,25 +722,22 @@ static const struct file_operations version_proc_fops = { #define PROC_TOSHIBA "toshiba" -static acpi_status __init add_device(void) +static void __init add_device(void) { proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops); proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops); proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops); proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops); proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops); - - return AE_OK; } -static acpi_status remove_device(void) +static void remove_device(void) { remove_proc_entry("lcd", toshiba_proc_dir); remove_proc_entry("video", toshiba_proc_dir); remove_proc_entry("fan", toshiba_proc_dir); remove_proc_entry("keys", toshiba_proc_dir); remove_proc_entry("version", toshiba_proc_dir); - return AE_OK; } static struct backlight_ops toshiba_backlight_data = { @@ -923,7 +920,6 @@ static void toshiba_acpi_exit(void) static int __init toshiba_acpi_init(void) { - acpi_status status = AE_OK; u32 hci_result; bool bt_present; int ret = 0; @@ -971,11 +967,7 @@ static int __init toshiba_acpi_init(void) toshiba_acpi_exit(); return -ENODEV; } else { - status = add_device(); - if (ACPI_FAILURE(status)) { - toshiba_acpi_exit(); - return -ENODEV; - } + add_device(); } props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; -- cgit v0.10.2 From bc28596a8fe5034ef776b0be2e0bf5629a31f746 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:51 -0700 Subject: hp-wmi: add return value checking for input_allocate_device() Add error checking and return -ENOMEM if input_allocate_device() fail. Signed-off-by: Axel Lin Acked-by: Thomas Renninger Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 34b4178..c5f95d1 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -527,6 +527,8 @@ static int __init hp_wmi_input_setup(void) int err; hp_wmi_input_dev = input_allocate_device(); + if (!hp_wmi_input_dev) + return -ENOMEM; hp_wmi_input_dev->name = "HP WMI hotkeys"; hp_wmi_input_dev->phys = "wmi/input0"; -- cgit v0.10.2 From f8ef3aecabe0e386303d028d02b6e5b23ac3a566 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:51 -0700 Subject: toshiba_acpi: rename add_device() and remove_device() to create_toshiba_proc_entries() and remove_toshiba_proc_entries() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To improve readability rename add_device() to create_toshiba_proc_entries() and rename remove_device() to remove_toshiba_proc_entries(). Signed-off-by: Axel Lin Cc: Matthew Garrett Cc: Márton Németh Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index c8bb7eb..627fc38 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -722,7 +722,7 @@ static const struct file_operations version_proc_fops = { #define PROC_TOSHIBA "toshiba" -static void __init add_device(void) +static void __init create_toshiba_proc_entries(void) { proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops); proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops); @@ -731,7 +731,7 @@ static void __init add_device(void) proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops); } -static void remove_device(void) +static void remove_toshiba_proc_entries(void) { remove_proc_entry("lcd", toshiba_proc_dir); remove_proc_entry("video", toshiba_proc_dir); @@ -905,7 +905,7 @@ static void toshiba_acpi_exit(void) if (toshiba_backlight_device) backlight_device_unregister(toshiba_backlight_device); - remove_device(); + remove_toshiba_proc_entries(); if (toshiba_proc_dir) remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); @@ -967,7 +967,7 @@ static int __init toshiba_acpi_init(void) toshiba_acpi_exit(); return -ENODEV; } else { - add_device(); + create_toshiba_proc_entries(); } props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; -- cgit v0.10.2 From 669048639ca6d3fdfb2e75dd77b8f49434d57625 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:52 -0700 Subject: acer-wmi: fix memory leaks in WMID_set_capabilities and get_wmid_devices When acpi_evaluate_object() is passed ACPI_ALLOCATE_BUFFER, the caller must kfree the returned buffer if AE_OK is returned. The callers of wmi_query_block() pass ACPI_ALLOCATE_BUFFER, and thus must check its return value before accessing or kfree() on the buffer. This patch adds a missing kfree(out.pointer) before exit WMID_set_capabilities() and get_wmid_devices(). Signed-off-by: Axel Lin Acked-by: Carlos Corbacho Cc: Matthew Garrett Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index dec558e..652ca18 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -772,6 +772,7 @@ static acpi_status WMID_set_capabilities(void) obj->buffer.length == sizeof(u32)) { devices = *((u32 *) obj->buffer.pointer); } else { + kfree(out.pointer); return AE_ERROR; } @@ -788,6 +789,7 @@ static acpi_status WMID_set_capabilities(void) if (!(devices & 0x20)) max_brightness = 0x9; + kfree(out.pointer); return status; } @@ -1094,6 +1096,7 @@ static u32 get_wmid_devices(void) struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; union acpi_object *obj; acpi_status status; + u32 devices = 0; status = wmi_query_block(WMID_GUID2, 1, &out); if (ACPI_FAILURE(status)) @@ -1102,10 +1105,11 @@ static u32 get_wmid_devices(void) obj = (union acpi_object *) out.pointer; if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == sizeof(u32)) { - return *((u32 *) obj->buffer.pointer); - } else { - return 0; + devices = *((u32 *) obj->buffer.pointer); } + + kfree(out.pointer); + return devices; } /* -- cgit v0.10.2 From 7677fbdff16f5b817bc3dc5d194a8b3350f8f9cb Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:53 -0700 Subject: acer-wmi: fix memory leaks in wmab_execute error path When acpi_evaluate_object() is passed ACPI_ALLOCATE_BUFFER, the caller must kfree the returned buffer if AE_OK is returned. Call Trace: wmab_execute -> wmi_evaluate_method -> acpi_evaluate_object Thus if callers of wmab_execute() pass ACPI_ALLOCATE_BUFFER, the return buffer must be kfreed if wmab_execute return AE_OK. [akpm@linux-foundation.org: avoid multiple return points, remove unneeded cast, remove unneeded initialisation of `status'] Signed-off-by: Axel Lin Acked-by: Carlos Corbacho Cc: Matthew Garrett Cc: Thomas Renninger Cc: Alan Jenkins Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index 652ca18..b066786 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -555,6 +555,7 @@ static acpi_status AMW0_find_mailled(void) obj->buffer.length == sizeof(struct wmab_ret)) { ret = *((struct wmab_ret *) obj->buffer.pointer); } else { + kfree(out.pointer); return AE_ERROR; } @@ -570,7 +571,7 @@ static acpi_status AMW0_set_capabilities(void) { struct wmab_args args; struct wmab_ret ret; - acpi_status status = AE_OK; + acpi_status status; struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; @@ -593,12 +594,13 @@ static acpi_status AMW0_set_capabilities(void) if (ACPI_FAILURE(status)) return status; - obj = (union acpi_object *) out.pointer; + obj = out.pointer; if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == sizeof(struct wmab_ret)) { ret = *((struct wmab_ret *) obj->buffer.pointer); } else { - return AE_ERROR; + status = AE_ERROR; + goto out; } if (ret.eax & 0x1) @@ -607,23 +609,26 @@ static acpi_status AMW0_set_capabilities(void) args.ebx = 2 << 8; args.ebx |= ACER_AMW0_BLUETOOTH_MASK; + /* + * It's ok to use existing buffer for next wmab_execute call. + * But we need to kfree(out.pointer) if next wmab_execute fail. + */ status = wmab_execute(&args, &out); if (ACPI_FAILURE(status)) - return status; + goto out; obj = (union acpi_object *) out.pointer; if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == sizeof(struct wmab_ret)) { ret = *((struct wmab_ret *) obj->buffer.pointer); } else { - return AE_ERROR; + status = AE_ERROR; + goto out; } if (ret.eax & 0x1) interface->capability |= ACER_CAP_BLUETOOTH; - kfree(out.pointer); - /* * This appears to be safe to enable, since all Wistron based laptops * appear to use the same EC register for brightness, even if they @@ -632,7 +637,10 @@ static acpi_status AMW0_set_capabilities(void) if (quirks->brightness >= 0) interface->capability |= ACER_CAP_BRIGHTNESS; - return AE_OK; + status = AE_OK; +out: + kfree(out.pointer); + return status; } static struct wmi_interface AMW0_interface = { -- cgit v0.10.2 From ff2367d1d5b8f76005899cd636fac5b82a881ab0 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:54 -0700 Subject: acer-wmi: remove non-used acer_quirks struct definition Remove non-used acer_quirks struct definition. Signed-off-by: Axel Lin Cc: Carlos Corbacho Cc: Matthew Garrett Cc: Thomas Renninger Cc: Alan Jenkins Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c index b066786..2badee2 100644 --- a/drivers/platform/x86/acer-wmi.c +++ b/drivers/platform/x86/acer-wmi.c @@ -50,17 +50,6 @@ MODULE_LICENSE("GPL"); #define ACER_INFO KERN_INFO ACER_LOGPREFIX /* - * The following defines quirks to get some specific functions to work - * which are known to not be supported over ACPI-WMI (such as the mail LED - * on WMID based Acer's) - */ -struct acer_quirks { - const char *vendor; - const char *model; - u16 quirks; -}; - -/* * Magic Number * Meaning is unknown - this number is required for writing to ACPI for AMW0 * (it's also used in acerhk when directly accessing the BIOS) -- cgit v0.10.2 From c26d85cb90e178d1e3df6a78d064f8731f154a5e Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:55 -0700 Subject: asus-laptop: fix wapf, wlan_status and bluetooth_status module_param permissions The wapf module parameters defines the behavior of the Fn+Fx wlan key. The wlan_status and bluetooth_status module parameters are for setting the wlan/bluetooth status on boot. All above module parameters are determinated only at the module load time. Change the value after the module is loaded does not make sense and has no effect at all, thus set the permissions to 0444 instead of 0644. Signed-off-by: Axel Lin Cc: Corentin Chary Cc: Matthew Garrett Cc: Alan Jenkins Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index 40897ba..6aba246 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -76,18 +76,18 @@ MODULE_LICENSE("GPL"); * So, if something doesn't work as you want, just try other values =) */ static uint wapf = 1; -module_param(wapf, uint, 0644); +module_param(wapf, uint, 0444); MODULE_PARM_DESC(wapf, "WAPF value"); static int wlan_status = 1; static int bluetooth_status = 1; -module_param(wlan_status, int, 0644); +module_param(wlan_status, int, 0444); MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot " "(0 = disabled, 1 = enabled, -1 = don't do anything). " "default is 1"); -module_param(bluetooth_status, int, 0644); +module_param(bluetooth_status, int, 0444); MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot " "(0 = disabled, 1 = enabled, -1 = don't do anything). " "default is 1"); -- cgit v0.10.2 From bfa47960f957c021a4d626b051668d2f66cadf23 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Tue, 20 Jul 2010 15:19:55 -0700 Subject: eeepc-laptop: fix hotplug_disabled module_param permissions The hotplug_disabled module parameter is determinated at the module load time. Change the value after the module is loaded does not make sense and has no effect at all, thus set the permissions to 0444 instead of 0644. Signed-off-by: Axel Lin Cc: Corentin Chary Cc: Matthew Garrett Cc: Alan Jenkins Signed-off-by: Andrew Morton Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index 0306174..6b8e062 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -53,7 +53,7 @@ MODULE_LICENSE("GPL"); static bool hotplug_disabled; -module_param(hotplug_disabled, bool, 0644); +module_param(hotplug_disabled, bool, 0444); MODULE_PARM_DESC(hotplug_disabled, "Disable hotplug for wireless device. " "If your laptop need that, please report to " -- cgit v0.10.2 From 9fab10cdf58099beff08d74f6b4a6633305c5754 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Wed, 7 Jul 2010 08:21:48 +0800 Subject: panasonic-laptop: fix acpi_pcc_write_sset return value In current implementation, acpi_pcc_write_sset return 1 if write is successful, 0 if write is failed. But all the callers consider acpi_pcc_write_sset return 0 if write is successful and return negtive if write is failed. This patch changes the implementation of acpi_pcc_write_sset to return 0 if write is successful, -EIO if write is failed. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c index 2fb9a32..ec01c3d 100644 --- a/drivers/platform/x86/panasonic-laptop.c +++ b/drivers/platform/x86/panasonic-laptop.c @@ -248,7 +248,7 @@ static int acpi_pcc_write_sset(struct pcc_acpi *pcc, int func, int val) status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SSET, ¶ms, NULL); - return status == AE_OK; + return (status == AE_OK) ? 0 : -EIO; } static inline int acpi_pcc_get_sqty(struct acpi_device *device) @@ -586,7 +586,6 @@ static int acpi_pcc_init_input(struct pcc_acpi *pcc) static int acpi_pcc_hotkey_resume(struct acpi_device *device) { struct pcc_acpi *pcc = acpi_driver_data(device); - acpi_status status = AE_OK; if (device == NULL || pcc == NULL) return -EINVAL; @@ -594,9 +593,7 @@ static int acpi_pcc_hotkey_resume(struct acpi_device *device) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n", pcc->sticky_mode)); - status = acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_mode); - - return status == AE_OK ? 0 : -EINVAL; + return acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_mode); } static int acpi_pcc_hotkey_add(struct acpi_device *device) -- cgit v0.10.2 From 49c6c5ff924cecc0b6260109a510b7ed4c970dc5 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:34 +0200 Subject: ACPI: Remove /proc/acpi/embedded_controller/.. Other patches in this series add the same info to /sys/... and /proc/ioports. The info removed should never have been used in an application, eventually someone read it manually. /proc/acpi is deprecated for more than a year anyway... Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 5f2027d..ce1f07f 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -34,8 +34,6 @@ #include #include #include -#include -#include #include #include #include @@ -679,72 +677,6 @@ acpi_ec_space_handler(u32 function, acpi_physical_address address, } /* -------------------------------------------------------------------------- - FS Interface (/proc) - -------------------------------------------------------------------------- */ - -static struct proc_dir_entry *acpi_ec_dir; - -static int acpi_ec_read_info(struct seq_file *seq, void *offset) -{ - struct acpi_ec *ec = seq->private; - - if (!ec) - goto end; - - seq_printf(seq, "gpe:\t\t\t0x%02x\n", (u32) ec->gpe); - seq_printf(seq, "ports:\t\t\t0x%02x, 0x%02x\n", - (unsigned)ec->command_addr, (unsigned)ec->data_addr); - seq_printf(seq, "use global lock:\t%s\n", - ec->global_lock ? "yes" : "no"); - end: - return 0; -} - -static int acpi_ec_info_open_fs(struct inode *inode, struct file *file) -{ - return single_open(file, acpi_ec_read_info, PDE(inode)->data); -} - -static const struct file_operations acpi_ec_info_ops = { - .open = acpi_ec_info_open_fs, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; - -static int acpi_ec_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_ec_dir); - if (!acpi_device_dir(device)) - return -ENODEV; - } - - entry = proc_create_data(ACPI_EC_FILE_INFO, S_IRUGO, - acpi_device_dir(device), - &acpi_ec_info_ops, acpi_driver_data(device)); - if (!entry) - return -ENODEV; - return 0; -} - -static int acpi_ec_remove_fs(struct acpi_device *device) -{ - - if (acpi_device_dir(device)) { - remove_proc_entry(ACPI_EC_FILE_INFO, acpi_device_dir(device)); - remove_proc_entry(acpi_device_bid(device), acpi_ec_dir); - acpi_device_dir(device) = NULL; - } - - return 0; -} - -/* -------------------------------------------------------------------------- Driver Interface -------------------------------------------------------------------------- */ static acpi_status @@ -894,7 +826,6 @@ static int acpi_ec_add(struct acpi_device *device) if (!first_ec) first_ec = ec; device->driver_data = ec; - acpi_ec_add_fs(device); pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", ec->gpe, ec->command_addr, ec->data_addr); @@ -921,7 +852,6 @@ static int acpi_ec_remove(struct acpi_device *device, int type) kfree(handler); } mutex_unlock(&ec->lock); - acpi_ec_remove_fs(device); device->driver_data = NULL; if (ec == first_ec) first_ec = NULL; @@ -1120,16 +1050,10 @@ int __init acpi_ec_init(void) { int result = 0; - acpi_ec_dir = proc_mkdir(ACPI_EC_CLASS, acpi_root_dir); - if (!acpi_ec_dir) - return -ENODEV; - /* Now register the driver for the EC */ result = acpi_bus_register_driver(&acpi_ec_driver); - if (result < 0) { - remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); + if (result < 0) return -ENODEV; - } return result; } @@ -1140,9 +1064,6 @@ static void __exit acpi_ec_exit(void) { acpi_bus_unregister_driver(&acpi_ec_driver); - - remove_proc_entry(ACPI_EC_CLASS, acpi_root_dir); - return; } #endif /* 0 */ -- cgit v0.10.2 From a420e46412ad9d33c7174cd4311b91728122e2c4 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:35 +0200 Subject: X86 platform drivers: Remove EC dump from thinkpad_acpi There is a general interface for that now (provided by other patches in this patch series): /sys/kernel/debug/ec/*/io Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org CC: Henrique de Moraes Holschuh CC: ibm-acpi-devel@lists.sourceforge.net Signed-off-by: Matthew Garrett diff --git a/Documentation/laptops/thinkpad-acpi.txt b/Documentation/laptops/thinkpad-acpi.txt index fc15538..f6f8025 100644 --- a/Documentation/laptops/thinkpad-acpi.txt +++ b/Documentation/laptops/thinkpad-acpi.txt @@ -960,70 +960,21 @@ Sysfs notes: subsystem, and follow all of the hwmon guidelines at Documentation/hwmon. +EXPERIMENTAL: Embedded controller register dump +----------------------------------------------- -EXPERIMENTAL: Embedded controller register dump -- /proc/acpi/ibm/ecdump ------------------------------------------------------------------------- - -This 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. - -This feature dumps the values of 256 embedded controller -registers. Values which have changed since the last time the registers -were dumped are marked with a star: - -[root@x40 ibm-acpi]# cat /proc/acpi/ibm/ecdump -EC +00 +01 +02 +03 +04 +05 +06 +07 +08 +09 +0a +0b +0c +0d +0e +0f -EC 0x00: a7 47 87 01 fe 96 00 08 01 00 cb 00 00 00 40 00 -EC 0x10: 00 00 ff ff f4 3c 87 09 01 ff 42 01 ff ff 0d 00 -EC 0x20: 00 00 00 00 00 00 00 00 00 00 00 03 43 00 00 80 -EC 0x30: 01 07 1a 00 30 04 00 00 *85 00 00 10 00 50 00 00 -EC 0x40: 00 00 00 00 00 00 14 01 00 04 00 00 00 00 00 00 -EC 0x50: 00 c0 02 0d 00 01 01 02 02 03 03 03 03 *bc *02 *bc -EC 0x60: *02 *bc *02 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0x70: 00 00 00 00 00 12 30 40 *24 *26 *2c *27 *20 80 *1f 80 -EC 0x80: 00 00 00 06 *37 *0e 03 00 00 00 0e 07 00 00 00 00 -EC 0x90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xa0: *ff 09 ff 09 ff ff *64 00 *00 *00 *a2 41 *ff *ff *e0 00 -EC 0xb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xd0: 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xe0: 00 00 00 00 00 00 00 00 11 20 49 04 24 06 55 03 -EC 0xf0: 31 55 48 54 35 38 57 57 08 2f 45 73 07 65 6c 1a - -This feature can be used to determine the register holding the fan -speed on some models. To do that, do the following: +This feature is not included in the thinkpad driver anymore. +Instead the EC can be accessed through /sys/kernel/debug/ec with +a userspace tool which can be found here: +ftp://ftp.suse.com/pub/people/trenn/sources/ec +Use it to determine the register holding the fan +speed on some models. To do that, do the following: - make sure the battery is fully charged - make sure the fan is running - - run 'cat /proc/acpi/ibm/ecdump' several times, once per second or so - -The first step makes sure various charging-related values don't -vary. The second ensures that the fan-related values do vary, since -the fan speed fluctuates a bit. The third will (hopefully) mark the -fan register with a star: - -[root@x40 ibm-acpi]# cat /proc/acpi/ibm/ecdump -EC +00 +01 +02 +03 +04 +05 +06 +07 +08 +09 +0a +0b +0c +0d +0e +0f -EC 0x00: a7 47 87 01 fe 96 00 08 01 00 cb 00 00 00 40 00 -EC 0x10: 00 00 ff ff f4 3c 87 09 01 ff 42 01 ff ff 0d 00 -EC 0x20: 00 00 00 00 00 00 00 00 00 00 00 03 43 00 00 80 -EC 0x30: 01 07 1a 00 30 04 00 00 85 00 00 10 00 50 00 00 -EC 0x40: 00 00 00 00 00 00 14 01 00 04 00 00 00 00 00 00 -EC 0x50: 00 c0 02 0d 00 01 01 02 02 03 03 03 03 bc 02 bc -EC 0x60: 02 bc 02 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0x70: 00 00 00 00 00 12 30 40 24 27 2c 27 21 80 1f 80 -EC 0x80: 00 00 00 06 *be 0d 03 00 00 00 0e 07 00 00 00 00 -EC 0x90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xa0: ff 09 ff 09 ff ff 64 00 00 00 a2 41 ff ff e0 00 -EC 0xb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xd0: 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 -EC 0xe0: 00 00 00 00 00 00 00 00 11 20 49 04 24 06 55 03 -EC 0xf0: 31 55 48 54 35 38 57 57 08 2f 45 73 07 65 6c 1a - -Another set of values that varies often is the temperature + - use above mentioned tool to read out the EC + +Often fan and temperature values vary between readings. Since temperatures don't change vary fast, you can take several quick dumps to eliminate them. diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 4bdb137..5d6119b 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -5838,75 +5838,6 @@ static struct ibm_struct thermal_driver_data = { }; /************************************************************************* - * EC Dump subdriver - */ - -static u8 ecdump_regs[256]; - -static int ecdump_read(struct seq_file *m) -{ - int i, j; - u8 v; - - seq_printf(m, "EC " - " +00 +01 +02 +03 +04 +05 +06 +07" - " +08 +09 +0a +0b +0c +0d +0e +0f\n"); - for (i = 0; i < 256; i += 16) { - seq_printf(m, "EC 0x%02x:", i); - for (j = 0; j < 16; j++) { - if (!acpi_ec_read(i + j, &v)) - break; - if (v != ecdump_regs[i + j]) - seq_printf(m, " *%02x", v); - else - seq_printf(m, " %02x", v); - ecdump_regs[i + j] = v; - } - seq_putc(m, '\n'); - if (j != 16) - break; - } - - /* These are way too dangerous to advertise openly... */ -#if 0 - seq_printf(m, "commands:\t0x 0x" - " ( is 00-ff, is 00-ff)\n"); - seq_printf(m, "commands:\t0x " - " ( is 00-ff, is 0-255)\n"); -#endif - return 0; -} - -static int ecdump_write(char *buf) -{ - char *cmd; - int i, v; - - while ((cmd = next_cmd(&buf))) { - if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { - /* i and v set */ - } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { - /* i and v set */ - } else - return -EINVAL; - if (i >= 0 && i < 256 && v >= 0 && v < 256) { - if (!acpi_ec_write(i, v)) - return -EIO; - } else - return -EINVAL; - } - - return 0; -} - -static struct ibm_struct ecdump_driver_data = { - .name = "ecdump", - .read = ecdump_read, - .write = ecdump_write, - .flags.experimental = 1, -}; - -/************************************************************************* * Backlight/brightness subdriver */ @@ -8883,9 +8814,6 @@ static struct ibm_init_struct ibms_init[] __initdata = { .data = &thermal_driver_data, }, { - .data = &ecdump_driver_data, - }, - { .init = brightness_init, .data = &brightness_driver_data, }, @@ -8993,7 +8921,6 @@ TPACPI_PARAM(light); TPACPI_PARAM(cmos); TPACPI_PARAM(led); TPACPI_PARAM(beep); -TPACPI_PARAM(ecdump); TPACPI_PARAM(brightness); TPACPI_PARAM(volume); TPACPI_PARAM(fan); -- cgit v0.10.2 From 925b108918c9a2ac58b4fd0994f4a9e63e11521c Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:36 +0200 Subject: X86 platform driver: Fix section mismatch in wmi.c The .add function must not be declared __init. Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index 6c15720..b2978a0 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -810,7 +810,7 @@ static bool guid_already_parsed(const char *guid_string) /* * Parse the _WDG method for the GUID data blocks */ -static __init acpi_status parse_wdg(acpi_handle handle) +static acpi_status parse_wdg(acpi_handle handle) { struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; union acpi_object *obj; @@ -959,7 +959,7 @@ static int acpi_wmi_remove(struct acpi_device *device, int type) return 0; } -static int __init acpi_wmi_add(struct acpi_device *device) +static int acpi_wmi_add(struct acpi_device *device) { acpi_status status; int result = 0; -- cgit v0.10.2 From cd89e08fa020f5a882f922e3c9e2628235ca6715 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:37 +0200 Subject: Documentation: Add new /sys/kernel/debug/ec/* files to ABI Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett diff --git a/Documentation/ABI/testing/debugfs-ec b/Documentation/ABI/testing/debugfs-ec new file mode 100644 index 0000000..6546115 --- /dev/null +++ b/Documentation/ABI/testing/debugfs-ec @@ -0,0 +1,20 @@ +What: /sys/kernel/debug/ec/*/{gpe,use_global_lock,io} +Date: July 2010 +Contact: Thomas Renninger +Description: + +General information like which GPE is assigned to the EC and whether +the global lock should get used. +Knowing the EC GPE one can watch the amount of HW events related to +the EC here (XY -> GPE number from /sys/kernel/debug/ec/*/gpe): +/sys/firmware/acpi/interrupts/gpeXY + +The io file is binary and a userspace tool located here: +ftp://ftp.suse.com/pub/people/trenn/sources/ec/ +should get used to read out the 256 Embedded Controller registers +or writing to them. + +CAUTION: Do not write to the Embedded Controller if you don't know +what you are doing! Rebooting afterwards also is a good idea. +This can influence the way your machine is cooled and fans may +not get switched on again after you did a wrong write. -- cgit v0.10.2 From 1195a098168fcacfef1cd80d05358e52fb366bf6 Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:31 +0200 Subject: ACPI: Provide /sys/kernel/debug/ec/... This patch provides the same information through debugfs, which previously was provided through /proc/acpi/embedded_controller/*/info This is the gpe the EC is connected to and whether the global lock gets used. The io ports used are added to /proc/ioports in another patch. Beside the fact that /proc/acpi is deprecated for quite some time, this info is not needed for applications and thus can be moved to debugfs instead of a public interface like /sys. Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: Bjorn Helgaas CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index 7464115..f7226d1 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -104,6 +104,19 @@ config ACPI_SYSFS_POWER help Say N to disable power /sys interface +config ACPI_EC_DEBUGFS + tristate "EC read/write access through /sys/kernel/debug/ec" + default y + help + Say N to disable Embedded Controller /sys/kernel/debug interface + + An Embedded Controller typically is available on laptops and reads + sensor values like battery state and temperature. + The kernel access the EC through ACPI parsed code provided by BIOS + tables. + Thus this option is a debug option that helps to write ACPI drivers + and can be used to identify ACPI code or EC firmware bugs. + config ACPI_PROC_EVENT bool "Deprecated /proc/acpi/event support" depends on PROC_FS diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 6ee3316..833b582 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -60,6 +60,7 @@ obj-$(CONFIG_ACPI_SBS) += sbshc.o obj-$(CONFIG_ACPI_SBS) += sbs.o obj-$(CONFIG_ACPI_POWER_METER) += power_meter.o obj-$(CONFIG_ACPI_HED) += hed.o +obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o # processor has its own "processor." module_param namespace processor-y := processor_driver.o processor_throttling.o diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index ce1f07f..a79e1b1 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -43,10 +43,13 @@ #include #include +#include "internal.h" + #define ACPI_EC_CLASS "embedded_controller" #define ACPI_EC_DEVICE_NAME "Embedded Controller" #define ACPI_EC_FILE_INFO "info" +#undef PREFIX #define PREFIX "ACPI: EC: " /* EC status register */ @@ -104,19 +107,8 @@ struct transaction { bool done; }; -static struct acpi_ec { - acpi_handle handle; - unsigned long gpe; - unsigned long command_addr; - unsigned long data_addr; - unsigned long global_lock; - unsigned long flags; - struct mutex lock; - wait_queue_head_t wait; - struct list_head list; - struct transaction *curr; - spinlock_t curr_lock; -} *boot_ec, *first_ec; +struct acpi_ec *boot_ec, *first_ec; +EXPORT_SYMBOL(first_ec); static int EC_FLAGS_MSI; /* Out-of-spec MSI controller */ static int EC_FLAGS_VALIDATE_ECDT; /* ASUStec ECDTs need to be validated */ diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c new file mode 100644 index 0000000..834c21a --- /dev/null +++ b/drivers/acpi/ec_sys.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include "internal.h" + +MODULE_AUTHOR("Thomas Renninger "); +MODULE_DESCRIPTION("ACPI EC sysfs access driver"); +MODULE_LICENSE("GPL"); + +struct sysdev_class acpi_ec_sysdev_class = { + .name = "ec", +}; + +static struct dentry *acpi_ec_debugfs_dir; + +int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) +{ + struct dentry *dev_dir; + char name[64]; + if (ec_device_count == 0) { + acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL); + if (!acpi_ec_debugfs_dir) + return -ENOMEM; + } + + sprintf(name, "ec%u", ec_device_count); + dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir); + if (!dev_dir) { + if (ec_device_count == 0) + debugfs_remove_recursive(acpi_ec_debugfs_dir); + /* TBD: Proper cleanup for multiple ECs */ + return -ENOMEM; + } + + debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); + debugfs_create_bool("use_global_lock", 0444, dev_dir, + (u32 *)&first_ec->global_lock); + return 0; +} + +static int __init acpi_ec_sys_init(void) +{ + int err = 0; + if (first_ec) + err = acpi_ec_add_debugfs(first_ec, 0); + else + err = -ENODEV; + return err; +} + +static void __exit acpi_ec_sys_exit(void) +{ + debugfs_remove_recursive(acpi_ec_debugfs_dir); +} + +module_init(acpi_ec_sys_init); +module_exit(acpi_ec_sys_exit); diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index f8f190e..8ae2726 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -18,6 +18,11 @@ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _ACPI_INTERNAL_H_ +#define _ACPI_INTERNAL_H_ + +#include + #define PREFIX "ACPI: " int init_acpi_device_notify(void); @@ -46,6 +51,23 @@ void acpi_early_processor_set_pdc(void); /* -------------------------------------------------------------------------- Embedded Controller -------------------------------------------------------------------------- */ +struct acpi_ec { + acpi_handle handle; + unsigned long gpe; + unsigned long command_addr; + unsigned long data_addr; + unsigned long global_lock; + unsigned long flags; + struct mutex lock; + wait_queue_head_t wait; + struct list_head list; + struct transaction *curr; + spinlock_t curr_lock; + struct sys_device sysdev; +}; + +extern struct acpi_ec *first_ec; + int acpi_ec_init(void); int acpi_ec_ecdt_probe(void); int acpi_boot_ec_enable(void); @@ -63,3 +85,5 @@ int acpi_sleep_proc_init(void); #else static inline int acpi_sleep_proc_init(void) { return 0; } #endif + +#endif /* _ACPI_INTERNAL_H_ */ -- cgit v0.10.2 From 9827886dce77c47c378ce3154689cea2c45c731d Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:32 +0200 Subject: ACPI: Provide /sys/kernel/debug//ec/ec0/io for binary access to the EC A userspace app to easily read/write the EC can be found here: ftp://ftp.suse.com/pub/people/trenn/sources/ec/ec_access.c Multiple ECs are not supported, but shouldn't be hard to add as soon as the ec driver itself will support them. Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c index 834c21a..3ef9781 100644 --- a/drivers/acpi/ec_sys.c +++ b/drivers/acpi/ec_sys.c @@ -1,3 +1,13 @@ +/* + * ec_sys.c + * + * Copyright (C) 2010 SUSE Products GmbH/Novell + * Author: + * Thomas Renninger + * + * This work is licensed under the terms of the GNU GPL, version 2. + */ + #include #include #include @@ -7,12 +17,87 @@ MODULE_AUTHOR("Thomas Renninger "); MODULE_DESCRIPTION("ACPI EC sysfs access driver"); MODULE_LICENSE("GPL"); +#define EC_SPACE_SIZE 256 + struct sysdev_class acpi_ec_sysdev_class = { .name = "ec", }; static struct dentry *acpi_ec_debugfs_dir; +static int acpi_ec_open_io(struct inode *i, struct file *f) +{ + f->private_data = i->i_private; + return 0; +} + +static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + unsigned int size = EC_SPACE_SIZE; + u8 *data = (u8 *) buf; + loff_t init_off = *off; + int err = 0; + + if (*off >= size) + return 0; + if (*off + count >= size) { + size -= *off; + count = size; + } else + size = count; + + while (size) { + err = ec_read(*off, &data[*off - init_off]); + if (err) + return err; + *off += 1; + size--; + } + return count; +} + +static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + + unsigned int size = count; + loff_t init_off = *off; + u8 *data = (u8 *) buf; + int err = 0; + + if (*off >= EC_SPACE_SIZE) + return 0; + if (*off + count >= EC_SPACE_SIZE) { + size = EC_SPACE_SIZE - *off; + count = size; + } + + while (size) { + u8 byte_write = data[*off - init_off]; + err = ec_write(*off, byte_write); + if (err) + return err; + + *off += 1; + size--; + } + return count; +} + +static struct file_operations acpi_ec_io_ops = { + .owner = THIS_MODULE, + .open = acpi_ec_open_io, + .read = acpi_ec_read_io, + .write = acpi_ec_write_io, +}; + int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) { struct dentry *dev_dir; @@ -35,6 +120,7 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); debugfs_create_bool("use_global_lock", 0444, dev_dir, (u32 *)&first_ec->global_lock); + debugfs_create_file("io", 0666, dev_dir, ec, &acpi_ec_io_ops); return 0; } -- cgit v0.10.2 From b52e04216fcd86968c01ad0cfdb249375f19134d Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Fri, 16 Jul 2010 13:11:33 +0200 Subject: ACPI: Register EC io ports in /proc/ioports Formerly these have been exposed through /proc/.. Better register them where all IO ports should get registered and scream loud if someone else claims to use them. EC data and command port typically should show up like this then: ... 0060-0060 : keyboard 0062-0062 : EC data 0064-0064 : keyboard 0066-0066 : EC command 0070-0071 : rtc0 ... Signed-off-by: Thomas Renninger CC: Alexey Starikovskiy CC: Len Brown CC: linux-kernel@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: Bjorn Helgaas CC: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index a79e1b1..265a99c 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -864,10 +864,18 @@ ec_parse_io_ports(struct acpi_resource *resource, void *context) * the second address region returned is the status/command * port. */ - if (ec->data_addr == 0) + if (ec->data_addr == 0) { ec->data_addr = resource->data.io.minimum; - else if (ec->command_addr == 0) + WARN(!request_region(ec->data_addr, 1, "EC data"), + "Could not request EC data io port %lu", + ec->data_addr); + } + else if (ec->command_addr == 0) { ec->command_addr = resource->data.io.minimum; + WARN(!request_region(ec->command_addr, 1, "EC command"), + "Could not request EC command io port %lu", + ec->command_addr); + } else return AE_CTRL_TERMINATE; -- cgit v0.10.2 From 8950778704cf8483cc5cc0140f557adf0d3f45a5 Mon Sep 17 00:00:00 2001 From: Alek Du Date: Tue, 13 Jul 2010 10:56:25 +0100 Subject: gpio: Add PMIC GPIO block support Moorestown has PMIC chip which contains GPIO blocks. The PMIC chip is connected to Langwell by SPI interface. So this GPIO driver will be regarded as SPI GPIO expander though the actual GPIO access is through IPC and SRAM. The SPI master contoller will probe this device driver by parsing SPIB table. Cleaned up for new IPC, GPE removed and some printk and other tidying by Alan Cox. Fixes for points noted by Matthew Garrett Signed-off-by: Alek Du Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index 2189565..ca30e56 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -540,6 +540,13 @@ config INTEL_SCU_IPC some embedded Intel x86 platforms. This is not needed for PC-type machines. +config GPIO_INTEL_PMIC + bool "Intel PMIC GPIO support" + depends on INTEL_SCU_IPC && GPIOLIB + ---help--- + Say Y here to support GPIO via the SCU IPC interface + on Intel MID platforms. + config RAR_REGISTER bool "Restricted Access Region Register Driver" depends on PCI && X86_MRST diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile index ed50eca..4744c77 100644 --- a/drivers/platform/x86/Makefile +++ b/drivers/platform/x86/Makefile @@ -28,3 +28,5 @@ obj-$(CONFIG_TOSHIBA_BT_RFKILL) += toshiba_bluetooth.o obj-$(CONFIG_INTEL_SCU_IPC) += intel_scu_ipc.o obj-$(CONFIG_RAR_REGISTER) += intel_rar_register.o obj-$(CONFIG_INTEL_IPS) += intel_ips.o +obj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o + diff --git a/drivers/platform/x86/intel_pmic_gpio.c b/drivers/platform/x86/intel_pmic_gpio.c new file mode 100644 index 0000000..5cdcff6 --- /dev/null +++ b/drivers/platform/x86/intel_pmic_gpio.c @@ -0,0 +1,340 @@ +/* Moorestown PMIC GPIO (access through IPC) driver + * Copyright (c) 2008 - 2009, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* Supports: + * Moorestown platform PMIC chip + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRIVER_NAME "pmic_gpio" + +/* register offset that IPC driver should use + * 8 GPIO + 8 GPOSW (6 controllable) + 8GPO + */ +enum pmic_gpio_register { + GPIO0 = 0xE0, + GPIO7 = 0xE7, + GPIOINT = 0xE8, + GPOSWCTL0 = 0xEC, + GPOSWCTL5 = 0xF1, + GPO = 0xF4, +}; + +/* bits definition for GPIO & GPOSW */ +#define GPIO_DRV 0x01 +#define GPIO_DIR 0x02 +#define GPIO_DIN 0x04 +#define GPIO_DOU 0x08 +#define GPIO_INTCTL 0x30 +#define GPIO_DBC 0xc0 + +#define GPOSW_DRV 0x01 +#define GPOSW_DOU 0x08 +#define GPOSW_RDRV 0x30 + + +#define NUM_GPIO 24 + +struct pmic_gpio_irq { + spinlock_t lock; + u32 trigger[NUM_GPIO]; + u32 dirty; + struct work_struct work; +}; + + +struct pmic_gpio { + struct gpio_chip chip; + struct pmic_gpio_irq irqtypes; + void *gpiointr; + int irq; + unsigned irq_base; +}; + +static void pmic_program_irqtype(int gpio, int type) +{ + if (type & IRQ_TYPE_EDGE_RISING) + intel_scu_ipc_update_register(GPIO0 + gpio, 0x20, 0x20); + else + intel_scu_ipc_update_register(GPIO0 + gpio, 0x00, 0x20); + + if (type & IRQ_TYPE_EDGE_FALLING) + intel_scu_ipc_update_register(GPIO0 + gpio, 0x10, 0x10); + else + intel_scu_ipc_update_register(GPIO0 + gpio, 0x00, 0x10); +}; + +static void pmic_irqtype_work(struct work_struct *work) +{ + struct pmic_gpio_irq *t = + container_of(work, struct pmic_gpio_irq, work); + unsigned long flags; + int i; + u16 type; + + spin_lock_irqsave(&t->lock, flags); + /* As we drop the lock, we may need multiple scans if we race the + pmic_irq_type function */ + while (t->dirty) { + /* + * For each pin that has the dirty bit set send an IPC + * message to configure the hardware via the PMIC + */ + for (i = 0; i < NUM_GPIO; i++) { + if (!(t->dirty & (1 << i))) + continue; + t->dirty &= ~(1 << i); + /* We can't trust the array entry or dirty + once the lock is dropped */ + type = t->trigger[i]; + spin_unlock_irqrestore(&t->lock, flags); + pmic_program_irqtype(i, type); + spin_lock_irqsave(&t->lock, flags); + } + } + spin_unlock_irqrestore(&t->lock, flags); +} + +static int pmic_gpio_direction_input(struct gpio_chip *chip, unsigned offset) +{ + if (offset > 8) { + printk(KERN_ERR + "%s: only pin 0-7 support input\n", __func__); + return -1;/* we only have 8 GPIO can use as input */ + } + return intel_scu_ipc_update_register(GPIO0 + offset, + GPIO_DIR, GPIO_DIR); +} + +static int pmic_gpio_direction_output(struct gpio_chip *chip, + unsigned offset, int value) +{ + int rc = 0; + + if (offset < 8)/* it is GPIO */ + rc = intel_scu_ipc_update_register(GPIO0 + offset, + GPIO_DRV | GPIO_DOU | GPIO_DIR, + GPIO_DRV | (value ? GPIO_DOU : 0)); + else if (offset < 16)/* it is GPOSW */ + rc = intel_scu_ipc_update_register(GPOSWCTL0 + offset - 8, + GPOSW_DRV | GPOSW_DOU | GPOSW_RDRV, + GPOSW_DRV | (value ? GPOSW_DOU : 0)); + else if (offset > 15 && offset < 24)/* it is GPO */ + rc = intel_scu_ipc_update_register(GPO, + 1 << (offset - 16), + value ? 1 << (offset - 16) : 0); + else { + printk(KERN_ERR + "%s: invalid PMIC GPIO pin %d!\n", __func__, offset); + WARN_ON(1); + } + + return rc; +} + +static int pmic_gpio_get(struct gpio_chip *chip, unsigned offset) +{ + u8 r; + int ret; + + /* we only have 8 GPIO pins we can use as input */ + if (offset > 8) + return -EOPNOTSUPP; + ret = intel_scu_ipc_ioread8(GPIO0 + offset, &r); + if (ret < 0) + return ret; + return r & GPIO_DIN; +} + +static void pmic_gpio_set(struct gpio_chip *chip, unsigned offset, int value) +{ + if (offset < 8)/* it is GPIO */ + intel_scu_ipc_update_register(GPIO0 + offset, + GPIO_DRV | GPIO_DOU, + GPIO_DRV | (value ? GPIO_DOU : 0)); + else if (offset < 16)/* it is GPOSW */ + intel_scu_ipc_update_register(GPOSWCTL0 + offset - 8, + GPOSW_DRV | GPOSW_DOU | GPOSW_RDRV, + GPOSW_DRV | (value ? GPOSW_DOU : 0)); + else if (offset > 15 && offset < 24) /* it is GPO */ + intel_scu_ipc_update_register(GPO, + 1 << (offset - 16), + value ? 1 << (offset - 16) : 0); +} + +static int pmic_irq_type(unsigned irq, unsigned type) +{ + struct pmic_gpio *pg = get_irq_chip_data(irq); + u32 gpio = irq - pg->irq_base; + unsigned long flags; + + if (gpio > pg->chip.ngpio) + return -EINVAL; + + spin_lock_irqsave(&pg->irqtypes.lock, flags); + pg->irqtypes.trigger[gpio] = type; + pg->irqtypes.dirty |= (1 << gpio); + spin_unlock_irqrestore(&pg->irqtypes.lock, flags); + schedule_work(&pg->irqtypes.work); + return 0; +} + + + +static int pmic_gpio_to_irq(struct gpio_chip *chip, unsigned offset) +{ + struct pmic_gpio *pg = container_of(chip, struct pmic_gpio, chip); + + return pg->irq_base + offset; +} + +/* the gpiointr register is read-clear, so just do nothing. */ +static void pmic_irq_unmask(unsigned irq) +{ +}; + +static void pmic_irq_mask(unsigned irq) +{ +}; + +static struct irq_chip pmic_irqchip = { + .name = "PMIC-GPIO", + .mask = pmic_irq_mask, + .unmask = pmic_irq_unmask, + .set_type = pmic_irq_type, +}; + +static void pmic_irq_handler(unsigned irq, struct irq_desc *desc) +{ + struct pmic_gpio *pg = (struct pmic_gpio *)get_irq_data(irq); + u8 intsts = *((u8 *)pg->gpiointr + 4); + int gpio; + + for (gpio = 0; gpio < 8; gpio++) { + if (intsts & (1 << gpio)) { + pr_debug("pmic pin %d triggered\n", gpio); + generic_handle_irq(pg->irq_base + gpio); + } + } + desc->chip->eoi(irq); +} + +static int __devinit platform_pmic_gpio_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + int irq = platform_get_irq(pdev, 0); + struct intel_pmic_gpio_platform_data *pdata = dev->platform_data; + + struct pmic_gpio *pg; + int retval; + int i; + + if (irq < 0) { + dev_dbg(dev, "no IRQ line\n"); + return -EINVAL; + } + + if (!pdata || !pdata->gpio_base || !pdata->irq_base) { + dev_dbg(dev, "incorrect or missing platform data\n"); + return -EINVAL; + } + + pg = kzalloc(sizeof(*pg), GFP_KERNEL); + if (!pg) + return -ENOMEM; + + dev_set_drvdata(dev, pg); + + pg->irq = irq; + /* setting up SRAM mapping for GPIOINT register */ + pg->gpiointr = ioremap_nocache(pdata->gpiointr, 8); + if (!pg->gpiointr) { + printk(KERN_ERR "%s: Can not map GPIOINT.\n", __func__); + retval = -EINVAL; + goto err2; + } + pg->irq_base = pdata->irq_base; + pg->chip.label = "intel_pmic"; + pg->chip.direction_input = pmic_gpio_direction_input; + pg->chip.direction_output = pmic_gpio_direction_output; + pg->chip.get = pmic_gpio_get; + pg->chip.set = pmic_gpio_set; + pg->chip.to_irq = pmic_gpio_to_irq; + pg->chip.base = pdata->gpio_base; + pg->chip.ngpio = NUM_GPIO; + pg->chip.can_sleep = 1; + pg->chip.dev = dev; + + INIT_WORK(&pg->irqtypes.work, pmic_irqtype_work); + spin_lock_init(&pg->irqtypes.lock); + + pg->chip.dev = dev; + retval = gpiochip_add(&pg->chip); + if (retval) { + printk(KERN_ERR "%s: Can not add pmic gpio chip.\n", __func__); + goto err; + } + set_irq_data(pg->irq, pg); + set_irq_chained_handler(pg->irq, pmic_irq_handler); + for (i = 0; i < 8; i++) { + set_irq_chip_and_handler_name(i + pg->irq_base, &pmic_irqchip, + handle_simple_irq, "demux"); + set_irq_chip_data(i + pg->irq_base, pg); + } + return 0; +err: + iounmap(pg->gpiointr); +err2: + kfree(pg); + return retval; +} + +/* at the same time, register a platform driver + * this supports the sfi 0.81 fw */ +static struct platform_driver platform_pmic_gpio_driver = { + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + }, + .probe = platform_pmic_gpio_probe, +}; + +static int __init platform_pmic_gpio_init(void) +{ + return platform_driver_register(&platform_pmic_gpio_driver); +} + +subsys_initcall(platform_pmic_gpio_init); + +MODULE_AUTHOR("Alek Du "); +MODULE_DESCRIPTION("Intel Moorestown PMIC GPIO driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/intel_pmic_gpio.h b/include/linux/intel_pmic_gpio.h new file mode 100644 index 0000000..920109a --- /dev/null +++ b/include/linux/intel_pmic_gpio.h @@ -0,0 +1,15 @@ +#ifndef LINUX_INTEL_PMIC_H +#define LINUX_INTEL_PMIC_H + +struct intel_pmic_gpio_platform_data { + /* the first IRQ of the chip */ + unsigned irq_base; + /* number assigned to the first GPIO */ + unsigned gpio_base; + /* sram address for gpiointr register, the langwell chip will map + * the PMIC spi GPIO expander's GPIOINTR register in sram. + */ + unsigned gpiointr; +}; + +#endif -- cgit v0.10.2 From 5ca56718917a353a7a916b182f6d7f1f2479c5bf Mon Sep 17 00:00:00 2001 From: Randy Dunlap Date: Fri, 23 Jul 2010 09:41:34 -0700 Subject: compal-laptop: depends on POWER_SUPPLY compal-laptop uses power_supply interfaces so it should depend on POWER_SUPPLY. ERROR: "power_supply_register" [drivers/platform/x86/compal-laptop.ko] undefined! ERROR: "power_supply_unregister" [drivers/platform/x86/compal-laptop.ko] undefined! Signed-off-by: Randy Dunlap Cc: Cezary Jackiewicz Cc: Matthew Garrett Cc: platform-driver-x86@vger.kernel.org Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index ca30e56..f6444af 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -183,6 +183,7 @@ config COMPAL_LAPTOP depends on BACKLIGHT_CLASS_DEVICE depends on RFKILL depends on HWMON + depends on POWER_SUPPLY ---help--- This is a driver for laptops built by Compal: -- cgit v0.10.2 From 6c3f6e6c575a0a992429427d4978c6091756a526 Mon Sep 17 00:00:00 2001 From: Pierre Ducroquet Date: Thu, 29 Jul 2010 11:56:59 +0200 Subject: toshiba-acpi: Add support for Toshiba Illumination. Add support for Toshiba Illumination. This is a set of LEDs installed on some Toshiba laptops. It is controlled through ACPI, the commands has been found through reverse engineering. It has been tested on a Toshiba Qosmio G50-122. Signed-off-by: Pierre Ducroquet Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c index 627fc38..7d67a45 100644 --- a/drivers/platform/x86/toshiba_acpi.c +++ b/drivers/platform/x86/toshiba_acpi.c @@ -4,6 +4,7 @@ * * Copyright (C) 2002-2004 John Belmonte * Copyright (C) 2008 Philip Langdale + * Copyright (C) 2010 Pierre Ducroquet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -47,6 +48,7 @@ #include #include #include +#include #include #include @@ -287,6 +289,7 @@ struct toshiba_acpi_dev { struct platform_device *p_dev; struct rfkill *bt_rfk; struct input_dev *hotkey_dev; + int illumination_installed; acpi_handle handle; const char *bt_name; @@ -294,6 +297,110 @@ struct toshiba_acpi_dev { struct mutex mutex; }; +/* Illumination support */ +static int toshiba_illumination_available(void) +{ + u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; + u32 out[HCI_WORDS]; + acpi_status status; + + in[0] = 0xf100; + status = hci_raw(in, out); + if (ACPI_FAILURE(status)) { + printk(MY_INFO "Illumination device not available\n"); + return 0; + } + in[0] = 0xf400; + status = hci_raw(in, out); + return 1; +} + +static void toshiba_illumination_set(struct led_classdev *cdev, + enum led_brightness brightness) +{ + u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; + u32 out[HCI_WORDS]; + acpi_status status; + + /* First request : initialize communication. */ + in[0] = 0xf100; + status = hci_raw(in, out); + if (ACPI_FAILURE(status)) { + printk(MY_INFO "Illumination device not available\n"); + return; + } + + if (brightness) { + /* Switch the illumination on */ + in[0] = 0xf400; + in[1] = 0x14e; + in[2] = 1; + status = hci_raw(in, out); + if (ACPI_FAILURE(status)) { + printk(MY_INFO "ACPI call for illumination failed.\n"); + return; + } + } else { + /* Switch the illumination off */ + in[0] = 0xf400; + in[1] = 0x14e; + in[2] = 0; + status = hci_raw(in, out); + if (ACPI_FAILURE(status)) { + printk(MY_INFO "ACPI call for illumination failed.\n"); + return; + } + } + + /* Last request : close communication. */ + in[0] = 0xf200; + in[1] = 0; + in[2] = 0; + hci_raw(in, out); +} + +static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) +{ + u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 }; + u32 out[HCI_WORDS]; + acpi_status status; + enum led_brightness result; + + /* First request : initialize communication. */ + in[0] = 0xf100; + status = hci_raw(in, out); + if (ACPI_FAILURE(status)) { + printk(MY_INFO "Illumination device not available\n"); + return LED_OFF; + } + + /* Check the illumination */ + in[0] = 0xf300; + in[1] = 0x14e; + status = hci_raw(in, out); + if (ACPI_FAILURE(status)) { + printk(MY_INFO "ACPI call for illumination failed.\n"); + return LED_OFF; + } + + result = out[2] ? LED_FULL : LED_OFF; + + /* Last request : close communication. */ + in[0] = 0xf200; + in[1] = 0; + in[2] = 0; + hci_raw(in, out); + + return result; +} + +static struct led_classdev toshiba_led = { + .name = "toshiba::illumination", + .max_brightness = 1, + .brightness_set = toshiba_illumination_set, + .brightness_get = toshiba_illumination_get, +}; + static struct toshiba_acpi_dev toshiba_acpi = { .bt_name = "Toshiba Bluetooth", }; @@ -913,6 +1020,9 @@ static void toshiba_acpi_exit(void) acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY, toshiba_acpi_notify); + if (toshiba_acpi.illumination_installed) + led_classdev_unregister(&toshiba_led); + platform_device_unregister(toshiba_acpi.p_dev); return; @@ -1007,6 +1117,13 @@ static int __init toshiba_acpi_init(void) } } + toshiba_acpi.illumination_installed = 0; + if (toshiba_illumination_available()) { + if (!led_classdev_register(&(toshiba_acpi.p_dev->dev), + &toshiba_led)) + toshiba_acpi.illumination_installed = 1; + } + return 0; } -- cgit v0.10.2 From 8700e1612e19f752be507f7fdcd8b48ba1b425ee Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 8 Jul 2010 09:50:30 +0800 Subject: msi-wmi: make needlessly global symbols static backlight is needlessly defined global. This patch makes the symbol static. Signed-off-by: Axel Lin Acked-by: Anisse Astier Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c index d173600..42a5469 100644 --- a/drivers/platform/x86/msi-wmi.c +++ b/drivers/platform/x86/msi-wmi.c @@ -57,7 +57,7 @@ static struct key_entry msi_wmi_keymap[] = { }; static ktime_t last_pressed[ARRAY_SIZE(msi_wmi_keymap) - 1]; -struct backlight_device *backlight; +static struct backlight_device *backlight; static int backlight_map[] = { 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF }; -- cgit v0.10.2 From 45036ae14a0161e9a0f542b6cb7ed55790f73f5b Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 5 Jul 2010 15:29:00 +0800 Subject: asus-laptop: fix asus_input_init error path This patch includes below fixes: 1. return -ENOMEM instead of 0 if input_allocate_device fail. 2. fix wrong goto if sparse_keymap_setup fail. 3. fix wrong goto if input_register_device fail. Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index 6aba246..b756e07 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -1124,7 +1124,7 @@ static int asus_input_init(struct asus_laptop *asus) input = input_allocate_device(); if (!input) { pr_info("Unable to allocate input device\n"); - return 0; + return -ENOMEM; } input->name = "Asus Laptop extra buttons"; input->phys = ASUS_LAPTOP_FILE "/input0"; @@ -1135,20 +1135,20 @@ static int asus_input_init(struct asus_laptop *asus) error = sparse_keymap_setup(input, asus_keymap, NULL); if (error) { pr_err("Unable to setup input device keymap\n"); - goto err_keymap; + goto err_free_dev; } error = input_register_device(input); if (error) { pr_info("Unable to register input device\n"); - goto err_device; + goto err_free_keymap; } asus->inputdev = input; return 0; -err_keymap: +err_free_keymap: sparse_keymap_free(input); -err_device: +err_free_dev: input_free_device(input); return error; } -- cgit v0.10.2 From 4519169b8f096957e4474e9a17206b2026dab0b3 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Mon, 5 Jul 2010 17:21:10 +0800 Subject: dell-laptop: make dell_laptop_i8042_filter() static Make dell_laptop_i8042_filter() static as it's used only in dell-laptop.c Signed-off-by: Axel Lin Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c index 9238218..b41ed5c 100644 --- a/drivers/platform/x86/dell-laptop.c +++ b/drivers/platform/x86/dell-laptop.c @@ -473,7 +473,7 @@ static struct backlight_ops dell_ops = { .update_status = dell_send_intensity, }; -bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, +static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, struct serio *port) { static bool extended; -- cgit v0.10.2 From c4775062d57c762de37ff93fb5f8611320c25e2a Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 29 Jul 2010 12:27:59 +0200 Subject: hp-wmi: Fix mixing up of and/or directive This should have been an "and". Additionally checking for !obj is even better. Signed-off-by: Thomas Renninger CC: linux-acpi@vger.kernel.or CC: platform-driver-x86@vger.kernel.org CC: mjg@redhat.com Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index c5f95d1..7e8a136 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -434,7 +434,9 @@ static void hp_wmi_notify(u32 value, void *context) obj = (union acpi_object *)response.pointer; - if (obj || obj->type != ACPI_TYPE_BUFFER) { + if (!obj) + return; + if (obj->type != ACPI_TYPE_BUFFER) { printk(KERN_INFO "hp-wmi: Unknown response received %d\n", obj->type); kfree(obj); -- cgit v0.10.2 From 7a0691c16f795cb7b69dcbaa61543e73b8865c4f Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 29 Jul 2010 12:28:00 +0200 Subject: hp-wmi: acpi_drivers.h is already included through acpi.h two lines below Signed-off-by: Thomas Renninger CC: linux-acpi@vger.kernel.or CC: platform-driver-x86@vger.kernel.org CC: mjg@redhat.com Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 7e8a136..f155163 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include -- cgit v0.10.2 From de4f10466e9347a2f1bfe39e501539557bed2c4b Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 29 Jul 2010 22:08:44 +0200 Subject: acpi ec: Fix possible double io port registration which will result in a harmless but ugly WARN message on some machines. Signed-off-by: Thomas Renninger CC: mjg59@srcf.ucam.org CC: platform-driver-x86@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: astarikovskiy@suse.de CC: akpm@linux-foundation.org Signed-off-by: Matthew Garrett diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 265a99c..1fa0aaf 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -818,6 +818,12 @@ static int acpi_ec_add(struct acpi_device *device) if (!first_ec) first_ec = ec; device->driver_data = ec; + + WARN(!request_region(ec->data_addr, 1, "EC data"), + "Could not request EC data io port 0x%lx", ec->data_addr); + WARN(!request_region(ec->command_addr, 1, "EC cmd"), + "Could not request EC cmd io port 0x%lx", ec->command_addr); + pr_info(PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", ec->gpe, ec->command_addr, ec->data_addr); @@ -844,6 +850,8 @@ static int acpi_ec_remove(struct acpi_device *device, int type) kfree(handler); } mutex_unlock(&ec->lock); + release_region(ec->data_addr, 1); + release_region(ec->command_addr, 1); device->driver_data = NULL; if (ec == first_ec) first_ec = NULL; @@ -864,18 +872,10 @@ ec_parse_io_ports(struct acpi_resource *resource, void *context) * the second address region returned is the status/command * port. */ - if (ec->data_addr == 0) { + if (ec->data_addr == 0) ec->data_addr = resource->data.io.minimum; - WARN(!request_region(ec->data_addr, 1, "EC data"), - "Could not request EC data io port %lu", - ec->data_addr); - } - else if (ec->command_addr == 0) { + else if (ec->command_addr == 0) ec->command_addr = resource->data.io.minimum; - WARN(!request_region(ec->command_addr, 1, "EC command"), - "Could not request EC command io port %lu", - ec->command_addr); - } else return AE_CTRL_TERMINATE; -- cgit v0.10.2 From 500de3dd46ac9f9ae9d124634c68907b7d50d2cb Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Thu, 29 Jul 2010 22:30:24 +0200 Subject: acpi ec_sys: Be more cautious about ec write access - Set Kconfig option default n - Only allow root to read/write io file (sever bug!) - Introduce write support module param -> default off - Properly clean up if any debugfs files cannot be created Signed-off-by: Thomas Renninger CC: mjg59@srcf.ucam.org CC: platform-driver-x86@vger.kernel.org CC: linux-acpi@vger.kernel.org CC: astarikovskiy@suse.de Signed-off-by: Matthew Garrett diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index f7226d1..08e0140 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -106,14 +106,19 @@ config ACPI_SYSFS_POWER config ACPI_EC_DEBUGFS tristate "EC read/write access through /sys/kernel/debug/ec" - default y + default n help Say N to disable Embedded Controller /sys/kernel/debug interface + Be aware that using this interface can confuse your Embedded + Controller in a way that a normal reboot is not enough. You then + have to power of your system, and remove the laptop battery for + some seconds. An Embedded Controller typically is available on laptops and reads sensor values like battery state and temperature. - The kernel access the EC through ACPI parsed code provided by BIOS - tables. + The kernel accesses the EC through ACPI parsed code provided by BIOS + tables. This option allows to access the EC directly without ACPI + code being involved. Thus this option is a debug option that helps to write ACPI drivers and can be used to identify ACPI code or EC firmware bugs. diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c index 3ef9781..0e869b3 100644 --- a/drivers/acpi/ec_sys.c +++ b/drivers/acpi/ec_sys.c @@ -17,6 +17,11 @@ MODULE_AUTHOR("Thomas Renninger "); MODULE_DESCRIPTION("ACPI EC sysfs access driver"); MODULE_LICENSE("GPL"); +static bool write_support; +module_param(write_support, bool, 0644); +MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may " + "be needed."); + #define EC_SPACE_SIZE 256 struct sysdev_class acpi_ec_sysdev_class = { @@ -102,6 +107,8 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) { struct dentry *dev_dir; char name[64]; + mode_t mode = 0400; + if (ec_device_count == 0) { acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL); if (!acpi_ec_debugfs_dir) @@ -111,17 +118,27 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) sprintf(name, "ec%u", ec_device_count); dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir); if (!dev_dir) { - if (ec_device_count == 0) - debugfs_remove_recursive(acpi_ec_debugfs_dir); - /* TBD: Proper cleanup for multiple ECs */ + if (ec_device_count != 0) + goto error; return -ENOMEM; } - debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); - debugfs_create_bool("use_global_lock", 0444, dev_dir, - (u32 *)&first_ec->global_lock); - debugfs_create_file("io", 0666, dev_dir, ec, &acpi_ec_io_ops); + if (!debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe)) + goto error; + if (!debugfs_create_bool("use_global_lock", 0444, dev_dir, + (u32 *)&first_ec->global_lock)) + goto error; + + if (write_support) + mode = 0600; + if (!debugfs_create_file("io", mode, dev_dir, ec, &acpi_ec_io_ops)) + goto error; + return 0; + +error: + debugfs_remove_recursive(acpi_ec_debugfs_dir); + return -ENOMEM; } static int __init acpi_ec_sys_init(void) -- cgit v0.10.2 From a00cd11b3986f4ab9b43f553785c3f9e8fb64323 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 3 Aug 2010 00:40:10 +0200 Subject: x86 plat: limit x86 platform driver menu to X86 My .config contains ACER_WMI=m. On SPARC. That does not make sense. Restrict the x86 platform driver menu to x86. Signed-off-by: Jan Engelhardt Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index f6444af..79baa63 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -5,6 +5,7 @@ menuconfig X86_PLATFORM_DEVICES bool "X86 Platform Specific Device Drivers" default y + depends on X86 ---help--- Say Y here to get to see options for device drivers for various x86 platforms, including vendor-specific laptop extension drivers. -- cgit v0.10.2 From 14d10f0a48cdfa76773cadcbf0deb233282f6b94 Mon Sep 17 00:00:00 2001 From: Sreedhara DS Date: Mon, 26 Jul 2010 10:02:25 +0100 Subject: intel_scu_ipc: detect CPU type automatically Intel SCU message formats depend upon the processor type. Replace the module option with automatic detection of the processor type. Signed-off-by: Sreedhara DS Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index bb2f1fb..b6a0344 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include /* IPC defines the following message types */ @@ -78,12 +78,9 @@ struct intel_scu_ipc_dev { static struct intel_scu_ipc_dev ipcdev; /* Only one for now */ -static int platform = 1; -module_param(platform, int, 0); -MODULE_PARM_DESC(platform, "1 for moorestown platform"); - - - +#define PLATFORM_LANGWELL 1 +#define PLATFORM_PENWELL 2 +static int platform; /* Platform type */ /* * IPC Read Buffer (Read Only): @@ -817,6 +814,14 @@ static struct pci_driver ipc_driver = { static int __init intel_scu_ipc_init(void) { + if (boot_cpu_data.x86 == 6 && + boot_cpu_data.x86_model == 0x27 && + boot_cpu_data.x86_mask == 1) + platform = PLATFORM_PENWELL; + else if (boot_cpu_data.x86 == 6 && + boot_cpu_data.x86_model == 0x26) + platform = PLATFORM_LANGWELL; + return pci_register_driver(&ipc_driver); } -- cgit v0.10.2 From e3359fd5d2d97f4d3bca5778e35427b07a2b1060 Mon Sep 17 00:00:00 2001 From: Sreedhara DS Date: Mon, 26 Jul 2010 10:02:46 +0100 Subject: intel_scu_ipc: Support Medfield processors Changes to work on bothMmoorestown and Medfield New pci id added for Medfield Return type of ipc_data_readl chnaged from u8 to u32 Signed-off-by: Sreedhara DS Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index b6a0344..a0dc41e 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -151,7 +151,7 @@ static inline u8 ipc_data_readb(u32 offset) /* Read ipc byte data */ return readb(ipcdev.ipc_base + IPC_READ_BUFFER + offset); } -static inline u8 ipc_data_readl(u32 offset) /* Read ipc u32 data */ +static inline u32 ipc_data_readl(u32 offset) /* Read ipc u32 data */ { return readl(ipcdev.ipc_base + IPC_READ_BUFFER + offset); } @@ -181,18 +181,19 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) int nc; u32 offset = 0; u32 err = 0; - u8 cbuf[IPC_WWBUF_SIZE] = { '\0' }; + u8 cbuf[IPC_WWBUF_SIZE] = { }; u32 *wbuf = (u32 *)&cbuf; mutex_lock(&ipclock); + if (ipcdev.pdev == NULL) { mutex_unlock(&ipclock); return -ENODEV; } - if (platform == 1) { + if (platform == PLATFORM_LANGWELL) { /* Entry is 4 bytes for read/write, 5 bytes for read modify */ - for (nc = 0; nc < count; nc++) { + for (nc = 0; nc < count; nc++, offset += 3) { cbuf[offset] = addr[nc]; cbuf[offset + 1] = addr[nc] >> 8; if (id != IPC_CMD_PCNTRL_R) @@ -201,33 +202,44 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) cbuf[offset + 3] = data[nc + 1]; offset += 1; } - offset += 3; } for (nc = 0, offset = 0; nc < count; nc++, offset += 4) ipc_data_writel(wbuf[nc], offset); /* Write wbuff */ + if (id != IPC_CMD_PCNTRL_M) + ipc_command((count*4) << 16 | id << 12 | 0 << 8 | op); + else + ipc_command((count*5) << 16 | id << 12 | 0 << 8 | op); + } else { - for (nc = 0, offset = 0; nc < count; nc++, offset += 2) - ipc_data_writel(addr[nc], offset); /* Write addresses */ - if (id != IPC_CMD_PCNTRL_R) { - for (nc = 0; nc < count; nc++, offset++) - ipc_data_writel(data[nc], offset); /* Write data */ - if (id == IPC_CMD_PCNTRL_M) - ipc_data_writel(data[nc + 1], offset); /* Mask value*/ + for (nc = 0; nc < count; nc++, offset += 2) { + cbuf[offset] = addr[nc]; + cbuf[offset + 1] = addr[nc] >> 8; } - } - if (id != IPC_CMD_PCNTRL_M) - ipc_command((count * 3) << 16 | id << 12 | 0 << 8 | op); - else - ipc_command((count * 4) << 16 | id << 12 | 0 << 8 | op); + if (id == IPC_CMD_PCNTRL_R) { + for (nc = 0, offset = 0; nc < count; nc++, offset += 4) + ipc_data_writel(wbuf[nc], offset); + ipc_command((count*2) << 16 | id << 12 | 0 << 8 | op); + } else if (id == IPC_CMD_PCNTRL_W) { + for (nc = 0; nc < count; nc++, offset += 1) + cbuf[offset] = data[nc]; + for (nc = 0, offset = 0; nc < count; nc++, offset += 4) + ipc_data_writel(wbuf[nc], offset); + ipc_command((count*3) << 16 | id << 12 | 0 << 8 | op); + } else if (id == IPC_CMD_PCNTRL_M) { + cbuf[offset] = data[0]; + cbuf[offset + 1] = data[1]; + ipc_data_writel(wbuf[0], 0); /* Write wbuff */ + ipc_command(4 << 16 | id << 12 | 0 << 8 | op); + } + } err = busy_loop(); - if (id == IPC_CMD_PCNTRL_R) { /* Read rbuf */ /* Workaround: values are read as 0 without memcpy_fromio */ - memcpy_fromio(cbuf, ipcdev.ipc_base + IPC_READ_BUFFER, 16); - if (platform == 1) { + memcpy_fromio(cbuf, ipcdev.ipc_base + 0x90, 16); + if (platform == PLATFORM_LANGWELL) { for (nc = 0, offset = 2; nc < count; nc++, offset += 3) data[nc] = ipc_data_readb(offset); } else { @@ -800,6 +812,7 @@ static void ipc_remove(struct pci_dev *pdev) static const struct pci_device_id pci_ids[] = { {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x080e)}, + {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x082a)}, { 0,} }; MODULE_DEVICE_TABLE(pci, pci_ids); -- cgit v0.10.2 From 804f8681a99da2aa49bd7f0dab3750848d1ab1bc Mon Sep 17 00:00:00 2001 From: Sreedhara DS Date: Mon, 26 Jul 2010 10:03:10 +0100 Subject: Remove indirect read write api support. The firmware of production devices does not support this interface so this is dead code. Signed-off-by: Sreedhara DS Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/arch/x86/include/asm/intel_scu_ipc.h b/arch/x86/include/asm/intel_scu_ipc.h index 0320045..29f6679 100644 --- a/arch/x86/include/asm/intel_scu_ipc.h +++ b/arch/x86/include/asm/intel_scu_ipc.h @@ -34,20 +34,6 @@ int intel_scu_ipc_writev(u16 *addr, u8 *data, int len); /* Update single register based on the mask */ int intel_scu_ipc_update_register(u16 addr, u8 data, u8 mask); -/* - * Indirect register read - * Can be used when SCCB(System Controller Configuration Block) register - * HRIM(Honor Restricted IPC Messages) is set (bit 23) - */ -int intel_scu_ipc_register_read(u32 addr, u32 *data); - -/* - * Indirect register write - * Can be used when SCCB(System Controller Configuration Block) register - * HRIM(Honor Restricted IPC Messages) is set (bit 23) - */ -int intel_scu_ipc_register_write(u32 addr, u32 data); - /* Issue commands to the SCU with or without data */ int intel_scu_ipc_simple_command(int cmd, int sub); int intel_scu_ipc_command(int cmd, int sub, u32 *in, int inlen, diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index a0dc41e..fd78386 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -116,24 +116,6 @@ static inline void ipc_data_writel(u32 data, u32 offset) /* Write ipc data */ } /* - * IPC destination Pointer (Write Only): - * Use content as pointer for destination write - */ -static inline void ipc_write_dptr(u32 data) /* Write dptr data */ -{ - writel(data, ipcdev.ipc_base + 0x0C); -} - -/* - * IPC Source Pointer (Write Only): - * Use content as pointer for read location -*/ -static inline void ipc_write_sptr(u32 data) /* Write dptr data */ -{ - writel(data, ipcdev.ipc_base + 0x08); -} - -/* * Status Register (Read Only): * Driver will read this register to get the ready/busy status of the IPC * block and error status of the IPC command that was just processed by SCU @@ -414,70 +396,6 @@ int intel_scu_ipc_update_register(u16 addr, u8 bits, u8 mask) EXPORT_SYMBOL(intel_scu_ipc_update_register); /** - * intel_scu_ipc_register_read - 32bit indirect read - * @addr: register address - * @value: 32bit value return - * - * Performs IA 32 bit indirect read, returns 0 on success, or an - * error code. - * - * Can be used when SCCB(System Controller Configuration Block) register - * HRIM(Honor Restricted IPC Messages) is set (bit 23) - * - * This function may sleep. Locking for SCU accesses is handled for - * the caller. - */ -int intel_scu_ipc_register_read(u32 addr, u32 *value) -{ - u32 err = 0; - - mutex_lock(&ipclock); - if (ipcdev.pdev == NULL) { - mutex_unlock(&ipclock); - return -ENODEV; - } - ipc_write_sptr(addr); - ipc_command(4 << 16 | IPC_CMD_INDIRECT_RD); - err = busy_loop(); - *value = ipc_data_readl(0); - mutex_unlock(&ipclock); - return err; -} -EXPORT_SYMBOL(intel_scu_ipc_register_read); - -/** - * intel_scu_ipc_register_write - 32bit indirect write - * @addr: register address - * @value: 32bit value to write - * - * Performs IA 32 bit indirect write, returns 0 on success, or an - * error code. - * - * Can be used when SCCB(System Controller Configuration Block) register - * HRIM(Honor Restricted IPC Messages) is set (bit 23) - * - * This function may sleep. Locking for SCU accesses is handled for - * the caller. - */ -int intel_scu_ipc_register_write(u32 addr, u32 value) -{ - u32 err = 0; - - mutex_lock(&ipclock); - if (ipcdev.pdev == NULL) { - mutex_unlock(&ipclock); - return -ENODEV; - } - ipc_write_dptr(addr); - ipc_data_writel(value, 0); - ipc_command(4 << 16 | IPC_CMD_INDIRECT_WR); - err = busy_loop(); - mutex_unlock(&ipclock); - return err; -} -EXPORT_SYMBOL(intel_scu_ipc_register_write); - -/** * intel_scu_ipc_simple_command - send a simple command * @cmd: command * @sub: sub type -- cgit v0.10.2 From a5b74e69e1238eb46a6fcf2b9dc9d0e4efbb4e46 Mon Sep 17 00:00:00 2001 From: Sreedhara DS Date: Mon, 26 Jul 2010 10:03:30 +0100 Subject: intel_scu_ipc: tidy up unused bits Delete unused constants IPC_CMD_INDIRECT_RD and IPC_CMD_INDIRECT_WR Remove multiple inclusion of header file "asm/mrst.h" Signed-off-by: Sreedhara DS Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index fd78386..2245876 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -38,10 +38,6 @@ #define IPC_CMD_PCNTRL_R 1 /* Register read */ #define IPC_CMD_PCNTRL_M 2 /* Register read-modify-write */ -/* Miscelaneous Command ids */ -#define IPC_CMD_INDIRECT_RD 2 /* 32bit indirect read */ -#define IPC_CMD_INDIRECT_WR 5 /* 32bit indirect write */ - /* * IPC register summary * -- cgit v0.10.2 From 9dd3adeb00b14d4b3d106360e2e33272deab35f3 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 26 Jul 2010 10:03:58 +0100 Subject: intel_scu_ipc: Use the new cpu identification function This provides an architecture level board identify function to replace the cpuid direct usage Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 2245876..5258749 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -74,8 +74,6 @@ struct intel_scu_ipc_dev { static struct intel_scu_ipc_dev ipcdev; /* Only one for now */ -#define PLATFORM_LANGWELL 1 -#define PLATFORM_PENWELL 2 static int platform; /* Platform type */ /* @@ -169,7 +167,7 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) return -ENODEV; } - if (platform == PLATFORM_LANGWELL) { + if (platform != MRST_CPU_CHIP_PENWELL) { /* Entry is 4 bytes for read/write, 5 bytes for read modify */ for (nc = 0; nc < count; nc++, offset += 3) { cbuf[offset] = addr[nc]; @@ -217,7 +215,7 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) if (id == IPC_CMD_PCNTRL_R) { /* Read rbuf */ /* Workaround: values are read as 0 without memcpy_fromio */ memcpy_fromio(cbuf, ipcdev.ipc_base + 0x90, 16); - if (platform == PLATFORM_LANGWELL) { + if (platform != MRST_CPU_CHIP_PENWELL) { for (nc = 0, offset = 2; nc < count; nc++, offset += 3) data[nc] = ipc_data_readb(offset); } else { @@ -741,14 +739,9 @@ static struct pci_driver ipc_driver = { static int __init intel_scu_ipc_init(void) { - if (boot_cpu_data.x86 == 6 && - boot_cpu_data.x86_model == 0x27 && - boot_cpu_data.x86_mask == 1) - platform = PLATFORM_PENWELL; - else if (boot_cpu_data.x86 == 6 && - boot_cpu_data.x86_model == 0x26) - platform = PLATFORM_LANGWELL; - + platform = mrst_identify_cpu(); + if (platform == 0) + return -ENODEV; return pci_register_driver(&ipc_driver); } -- cgit v0.10.2 From 51cd525dce018f298568d8e2e769b1a698ef91cd Mon Sep 17 00:00:00 2001 From: Arjan van de Ven Date: Mon, 26 Jul 2010 10:04:24 +0100 Subject: Fix stack buffer size for IPC writev messages The stack buffer for IPC messages was 16 bytes, limiting messages to a size of 4 (each message is 32 bit). However, the touch screen driver is trying to send messages of size 5.... (AC: Set to 20 bytes having checked the max size allowed) Signed-off-by: Arjan van de Ven Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 5258749..1b0d0d5 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -58,8 +58,8 @@ #define IPC_BASE_ADDR 0xFF11C000 /* IPC1 base register address */ #define IPC_MAX_ADDR 0x100 /* Maximum IPC regisers */ -#define IPC_WWBUF_SIZE 16 /* IPC Write buffer Size */ -#define IPC_RWBUF_SIZE 16 /* IPC Read buffer Size */ +#define IPC_WWBUF_SIZE 20 /* IPC Write buffer Size */ +#define IPC_RWBUF_SIZE 20 /* IPC Read buffer Size */ #define IPC_I2C_BASE 0xFF12B000 /* I2C control register base address */ #define IPC_I2C_MAX_ADDR 0x10 /* Maximum I2C regisers */ -- cgit v0.10.2 From ed6f2b4da32913875355f5c9cbbb38e4168b7801 Mon Sep 17 00:00:00 2001 From: Arjan van de Ven Date: Mon, 26 Jul 2010 10:04:37 +0100 Subject: zero the stack buffer before giving random garbage to the SCU some messages take 4 bytes, but only fill 3 bytes.... this patch makes sure that whatever we send to the SCU is zeroed first Signed-off-by: Arjan van de Ven Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 1b0d0d5..b903420f 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -162,6 +162,8 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) mutex_lock(&ipclock); + memset(cbuf, 0, sizeof(cbuf)); + if (ipcdev.pdev == NULL) { mutex_unlock(&ipclock); return -ENODEV; -- cgit v0.10.2 From 6c8d0fdbe88e8bb1a07fa9a2830767cc180f7d1b Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Mon, 26 Jul 2010 10:05:03 +0100 Subject: Clean up command packing on MRST. Don't pass more bytes in the command length field than we filled. Signed-off-by: Andy Ross Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index b903420f..5055c52 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -154,7 +154,7 @@ static inline int busy_loop(void) /* Wait till scu status is busy */ /* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) { - int nc; + int i, nc, bytes; u32 offset = 0; u32 err = 0; u8 cbuf[IPC_WWBUF_SIZE] = { }; @@ -170,25 +170,18 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) } if (platform != MRST_CPU_CHIP_PENWELL) { - /* Entry is 4 bytes for read/write, 5 bytes for read modify */ - for (nc = 0; nc < count; nc++, offset += 3) { - cbuf[offset] = addr[nc]; - cbuf[offset + 1] = addr[nc] >> 8; + bytes = 0; + for(i=0; i> 8; if (id != IPC_CMD_PCNTRL_R) - cbuf[offset + 2] = data[nc]; - if (id == IPC_CMD_PCNTRL_M) { - cbuf[offset + 3] = data[nc + 1]; - offset += 1; - } + cbuf[bytes++] = data[i]; + if (id == IPC_CMD_PCNTRL_M) + cbuf[bytes++] = data[i + 1]; } - for (nc = 0, offset = 0; nc < count; nc++, offset += 4) - ipc_data_writel(wbuf[nc], offset); /* Write wbuff */ - - if (id != IPC_CMD_PCNTRL_M) - ipc_command((count*4) << 16 | id << 12 | 0 << 8 | op); - else - ipc_command((count*5) << 16 | id << 12 | 0 << 8 | op); - + for(i=0; i Date: Mon, 26 Jul 2010 10:05:52 +0100 Subject: intel_scu_ipc: fix data packing of PMIC command on Moorestown Data is 2-byte per entry for PMIC read-modify-update command. Signed-off-by: Hong Liu Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 5055c52..84a2d4b 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -154,7 +154,7 @@ static inline int busy_loop(void) /* Wait till scu status is busy */ /* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) { - int i, nc, bytes; + int i, nc, bytes, d; u32 offset = 0; u32 err = 0; u8 cbuf[IPC_WWBUF_SIZE] = { }; @@ -171,15 +171,16 @@ static int pwr_reg_rdwr(u16 *addr, u8 *data, u32 count, u32 op, u32 id) if (platform != MRST_CPU_CHIP_PENWELL) { bytes = 0; - for(i=0; i> 8; if (id != IPC_CMD_PCNTRL_R) - cbuf[bytes++] = data[i]; + cbuf[bytes++] = data[d++]; if (id == IPC_CMD_PCNTRL_M) - cbuf[bytes++] = data[i + 1]; + cbuf[bytes++] = data[d++]; } - for(i=0; i Date: Mon, 26 Jul 2010 10:06:12 +0100 Subject: intel_scu_ipc: return -EIO for error condition in busy_loop Signed-off-by: Hong Liu Signed-off-by: Alan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 84a2d4b..23b6d46 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -148,7 +148,10 @@ static inline int busy_loop(void) /* Wait till scu status is busy */ return -ETIMEDOUT; } } - return (status >> 1) & 1; + if ((status >> 1) & 1) + return -EIO; + + return 0; } /* Read/Write power control(PMIC in Langwell, MSIC in PenWell) registers */ -- cgit v0.10.2 From 5aa06930fbcfcb6b03fcb18b753122b10ac47a87 Mon Sep 17 00:00:00 2001 From: Hong Liu Date: Mon, 26 Jul 2010 10:06:31 +0100 Subject: intel_scu_ipc: fix size field for intel_scu_ipc_command Size for PMIC read/write command is byte, while it is DWORD for other IPC commands. Signed-off-by: Hong Liu Signed-off-by: ALan Cox Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c index 23b6d46..943f908 100644 --- a/drivers/platform/x86/intel_scu_ipc.c +++ b/drivers/platform/x86/intel_scu_ipc.c @@ -444,7 +444,7 @@ int intel_scu_ipc_command(int cmd, int sub, u32 *in, int inlen, for (i = 0; i < inlen; i++) ipc_data_writel(*in++, 4 * i); - ipc_command((sub << 12) | cmd | (inlen << 18)); + ipc_command((inlen << 16) | (sub << 12) | cmd); err = busy_loop(); for (i = 0; i < outlen; i++) -- cgit v0.10.2 From 1a14703d6b20010401ca273ac1f07bff7992aa2c Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Wed, 28 Jul 2010 14:42:56 -0700 Subject: ips driver: make it less chatty We don't need a dev_warn when we exceed a thermal or power limit as we'll handle it appropriately by clamping down on the CPU, GPU or both as needed. Signed-off-by: Jesse Barnes Signed-off-by: Matthew Garrett diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c index 0344822..afe82e5 100644 --- a/drivers/platform/x86/intel_ips.c +++ b/drivers/platform/x86/intel_ips.c @@ -607,7 +607,7 @@ static bool mcp_exceeded(struct ips_driver *ips) spin_unlock_irqrestore(&ips->turbo_status_lock, flags); if (ret) - dev_warn(&ips->dev->dev, + dev_info(&ips->dev->dev, "MCP power or thermal limit exceeded\n"); return ret; @@ -635,7 +635,7 @@ static bool cpu_exceeded(struct ips_driver *ips, int cpu) spin_unlock_irqrestore(&ips->turbo_status_lock, flags); if (ret) - dev_warn(&ips->dev->dev, + dev_info(&ips->dev->dev, "CPU power or thermal limit exceeded\n"); return ret; -- cgit v0.10.2