aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86/msi-wmi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/platform/x86/msi-wmi.c')
-rw-r--r--drivers/platform/x86/msi-wmi.c62
1 files changed, 30 insertions, 32 deletions
diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
index 42a5469a2459..c832e3356cd6 100644
--- a/drivers/platform/x86/msi-wmi.c
+++ b/drivers/platform/x86/msi-wmi.c
@@ -20,6 +20,7 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 24
24#include <linux/kernel.h> 25#include <linux/kernel.h>
25#include <linux/input.h> 26#include <linux/input.h>
@@ -36,23 +37,22 @@ MODULE_ALIAS("wmi:551A1F84-FBDD-4125-91DB-3EA8F44F1D45");
36MODULE_ALIAS("wmi:B6F3EEF2-3D2F-49DC-9DE3-85BCE18C62F2"); 37MODULE_ALIAS("wmi:B6F3EEF2-3D2F-49DC-9DE3-85BCE18C62F2");
37 38
38#define DRV_NAME "msi-wmi" 39#define DRV_NAME "msi-wmi"
39#define DRV_PFX DRV_NAME ": "
40 40
41#define MSIWMI_BIOS_GUID "551A1F84-FBDD-4125-91DB-3EA8F44F1D45" 41#define MSIWMI_BIOS_GUID "551A1F84-FBDD-4125-91DB-3EA8F44F1D45"
42#define MSIWMI_EVENT_GUID "B6F3EEF2-3D2F-49DC-9DE3-85BCE18C62F2" 42#define MSIWMI_EVENT_GUID "B6F3EEF2-3D2F-49DC-9DE3-85BCE18C62F2"
43 43
44#define dprintk(msg...) pr_debug(DRV_PFX msg) 44#define SCANCODE_BASE 0xD0
45 45#define MSI_WMI_BRIGHTNESSUP SCANCODE_BASE
46#define KEYCODE_BASE 0xD0 46#define MSI_WMI_BRIGHTNESSDOWN (SCANCODE_BASE + 1)
47#define MSI_WMI_BRIGHTNESSUP KEYCODE_BASE 47#define MSI_WMI_VOLUMEUP (SCANCODE_BASE + 2)
48#define MSI_WMI_BRIGHTNESSDOWN (KEYCODE_BASE + 1) 48#define MSI_WMI_VOLUMEDOWN (SCANCODE_BASE + 3)
49#define MSI_WMI_VOLUMEUP (KEYCODE_BASE + 2) 49#define MSI_WMI_MUTE (SCANCODE_BASE + 4)
50#define MSI_WMI_VOLUMEDOWN (KEYCODE_BASE + 3)
51static struct key_entry msi_wmi_keymap[] = { 50static struct key_entry msi_wmi_keymap[] = {
52 { KE_KEY, MSI_WMI_BRIGHTNESSUP, {KEY_BRIGHTNESSUP} }, 51 { KE_KEY, MSI_WMI_BRIGHTNESSUP, {KEY_BRIGHTNESSUP} },
53 { KE_KEY, MSI_WMI_BRIGHTNESSDOWN, {KEY_BRIGHTNESSDOWN} }, 52 { KE_KEY, MSI_WMI_BRIGHTNESSDOWN, {KEY_BRIGHTNESSDOWN} },
54 { KE_KEY, MSI_WMI_VOLUMEUP, {KEY_VOLUMEUP} }, 53 { KE_KEY, MSI_WMI_VOLUMEUP, {KEY_VOLUMEUP} },
55 { KE_KEY, MSI_WMI_VOLUMEDOWN, {KEY_VOLUMEDOWN} }, 54 { KE_KEY, MSI_WMI_VOLUMEDOWN, {KEY_VOLUMEDOWN} },
55 { KE_KEY, MSI_WMI_MUTE, {KEY_MUTE} },
56 { KE_END, 0} 56 { KE_END, 0}
57}; 57};
58static ktime_t last_pressed[ARRAY_SIZE(msi_wmi_keymap) - 1]; 58static ktime_t last_pressed[ARRAY_SIZE(msi_wmi_keymap) - 1];
@@ -76,7 +76,7 @@ static int msi_wmi_query_block(int instance, int *ret)
76 76
77 if (!obj || obj->type != ACPI_TYPE_INTEGER) { 77 if (!obj || obj->type != ACPI_TYPE_INTEGER) {
78 if (obj) { 78 if (obj) {
79 printk(KERN_ERR DRV_PFX "query block returned object " 79 pr_err("query block returned object "
80 "type: %d - buffer length:%d\n", obj->type, 80 "type: %d - buffer length:%d\n", obj->type,
81 obj->type == ACPI_TYPE_BUFFER ? 81 obj->type == ACPI_TYPE_BUFFER ?
82 obj->buffer.length : 0); 82 obj->buffer.length : 0);
@@ -95,8 +95,8 @@ static int msi_wmi_set_block(int instance, int value)
95 95
96 struct acpi_buffer input = { sizeof(int), &value }; 96 struct acpi_buffer input = { sizeof(int), &value };
97 97
98 dprintk("Going to set block of instance: %d - value: %d\n", 98 pr_debug("Going to set block of instance: %d - value: %d\n",
99 instance, value); 99 instance, value);
100 100
101 status = wmi_set_block(MSIWMI_BIOS_GUID, instance, &input); 101 status = wmi_set_block(MSIWMI_BIOS_GUID, instance, &input);
102 102
@@ -110,20 +110,19 @@ static int bl_get(struct backlight_device *bd)
110 /* Instance 1 is "get backlight", cmp with DSDT */ 110 /* Instance 1 is "get backlight", cmp with DSDT */
111 err = msi_wmi_query_block(1, &ret); 111 err = msi_wmi_query_block(1, &ret);
112 if (err) { 112 if (err) {
113 printk(KERN_ERR DRV_PFX "Could not query backlight: %d\n", err); 113 pr_err("Could not query backlight: %d\n", err);
114 return -EINVAL; 114 return -EINVAL;
115 } 115 }
116 dprintk("Get: Query block returned: %d\n", ret); 116 pr_debug("Get: Query block returned: %d\n", ret);
117 for (level = 0; level < ARRAY_SIZE(backlight_map); level++) { 117 for (level = 0; level < ARRAY_SIZE(backlight_map); level++) {
118 if (backlight_map[level] == ret) { 118 if (backlight_map[level] == ret) {
119 dprintk("Current backlight level: 0x%X - index: %d\n", 119 pr_debug("Current backlight level: 0x%X - index: %d\n",
120 backlight_map[level], level); 120 backlight_map[level], level);
121 break; 121 break;
122 } 122 }
123 } 123 }
124 if (level == ARRAY_SIZE(backlight_map)) { 124 if (level == ARRAY_SIZE(backlight_map)) {
125 printk(KERN_ERR DRV_PFX "get: Invalid brightness value: 0x%X\n", 125 pr_err("get: Invalid brightness value: 0x%X\n", ret);
126 ret);
127 return -EINVAL; 126 return -EINVAL;
128 } 127 }
129 return level; 128 return level;
@@ -154,7 +153,7 @@ static void msi_wmi_notify(u32 value, void *context)
154 153
155 status = wmi_get_event_data(value, &response); 154 status = wmi_get_event_data(value, &response);
156 if (status != AE_OK) { 155 if (status != AE_OK) {
157 printk(KERN_INFO DRV_PFX "bad event status 0x%x\n", status); 156 pr_info("bad event status 0x%x\n", status);
158 return; 157 return;
159 } 158 }
160 159
@@ -162,40 +161,39 @@ static void msi_wmi_notify(u32 value, void *context)
162 161
163 if (obj && obj->type == ACPI_TYPE_INTEGER) { 162 if (obj && obj->type == ACPI_TYPE_INTEGER) {
164 int eventcode = obj->integer.value; 163 int eventcode = obj->integer.value;
165 dprintk("Eventcode: 0x%x\n", eventcode); 164 pr_debug("Eventcode: 0x%x\n", eventcode);
166 key = sparse_keymap_entry_from_scancode(msi_wmi_input_dev, 165 key = sparse_keymap_entry_from_scancode(msi_wmi_input_dev,
167 eventcode); 166 eventcode);
168 if (key) { 167 if (key) {
169 ktime_t diff; 168 ktime_t diff;
170 cur = ktime_get_real(); 169 cur = ktime_get_real();
171 diff = ktime_sub(cur, last_pressed[key->code - 170 diff = ktime_sub(cur, last_pressed[key->code -
172 KEYCODE_BASE]); 171 SCANCODE_BASE]);
173 /* Ignore event if the same event happened in a 50 ms 172 /* Ignore event if the same event happened in a 50 ms
174 timeframe -> Key press may result in 10-20 GPEs */ 173 timeframe -> Key press may result in 10-20 GPEs */
175 if (ktime_to_us(diff) < 1000 * 50) { 174 if (ktime_to_us(diff) < 1000 * 50) {
176 dprintk("Suppressed key event 0x%X - " 175 pr_debug("Suppressed key event 0x%X - "
177 "Last press was %lld us ago\n", 176 "Last press was %lld us ago\n",
178 key->code, ktime_to_us(diff)); 177 key->code, ktime_to_us(diff));
179 return; 178 return;
180 } 179 }
181 last_pressed[key->code - KEYCODE_BASE] = cur; 180 last_pressed[key->code - SCANCODE_BASE] = cur;
182 181
183 if (key->type == KE_KEY && 182 if (key->type == KE_KEY &&
184 /* Brightness is served via acpi video driver */ 183 /* Brightness is served via acpi video driver */
185 (!acpi_video_backlight_support() || 184 (!acpi_video_backlight_support() ||
186 (key->code != MSI_WMI_BRIGHTNESSUP && 185 (key->code != MSI_WMI_BRIGHTNESSUP &&
187 key->code != MSI_WMI_BRIGHTNESSDOWN))) { 186 key->code != MSI_WMI_BRIGHTNESSDOWN))) {
188 dprintk("Send key: 0x%X - " 187 pr_debug("Send key: 0x%X - "
189 "Input layer keycode: %d\n", key->code, 188 "Input layer keycode: %d\n",
190 key->keycode); 189 key->code, key->keycode);
191 sparse_keymap_report_entry(msi_wmi_input_dev, 190 sparse_keymap_report_entry(msi_wmi_input_dev,
192 key, 1, true); 191 key, 1, true);
193 } 192 }
194 } else 193 } else
195 printk(KERN_INFO "Unknown key pressed - %x\n", 194 pr_info("Unknown key pressed - %x\n", eventcode);
196 eventcode);
197 } else 195 } else
198 printk(KERN_INFO DRV_PFX "Unknown event received\n"); 196 pr_info("Unknown event received\n");
199 kfree(response.pointer); 197 kfree(response.pointer);
200} 198}
201 199
@@ -236,8 +234,7 @@ static int __init msi_wmi_init(void)
236 int err; 234 int err;
237 235
238 if (!wmi_has_guid(MSIWMI_EVENT_GUID)) { 236 if (!wmi_has_guid(MSIWMI_EVENT_GUID)) {
239 printk(KERN_ERR 237 pr_err("This machine doesn't have MSI-hotkeys through WMI\n");
240 "This machine doesn't have MSI-hotkeys through WMI\n");
241 return -ENODEV; 238 return -ENODEV;
242 } 239 }
243 err = wmi_install_notify_handler(MSIWMI_EVENT_GUID, 240 err = wmi_install_notify_handler(MSIWMI_EVENT_GUID,
@@ -252,6 +249,7 @@ static int __init msi_wmi_init(void)
252 if (!acpi_video_backlight_support()) { 249 if (!acpi_video_backlight_support()) {
253 struct backlight_properties props; 250 struct backlight_properties props;
254 memset(&props, 0, sizeof(struct backlight_properties)); 251 memset(&props, 0, sizeof(struct backlight_properties));
252 props.type = BACKLIGHT_PLATFORM;
255 props.max_brightness = ARRAY_SIZE(backlight_map) - 1; 253 props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
256 backlight = backlight_device_register(DRV_NAME, NULL, NULL, 254 backlight = backlight_device_register(DRV_NAME, NULL, NULL,
257 &msi_backlight_ops, 255 &msi_backlight_ops,
@@ -267,7 +265,7 @@ static int __init msi_wmi_init(void)
267 265
268 backlight->props.brightness = err; 266 backlight->props.brightness = err;
269 } 267 }
270 dprintk("Event handler installed\n"); 268 pr_debug("Event handler installed\n");
271 269
272 return 0; 270 return 0;
273 271