aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86
diff options
context:
space:
mode:
authorMaxim Mikityanskiy <maxtram95@gmail.com>2012-12-15 12:31:34 -0500
committerMatthew Garrett <matthew.garrett@nebula.com>2013-02-24 17:49:54 -0500
commitda8506288fc4b2cc62d0ba477c2fe2a16f8891b0 (patch)
tree83b2a000ad38cf0c88362223fe137aa821bdae3c /drivers/platform/x86
parentb0d3bb53beaba866ce80424fb512b1669ed88da0 (diff)
msi-wmi: Make keys and backlight independent
Introduced function msi_wmi_backlight_setup() that initializes backlight device. Made driver load and work if only one WMI (only for hotkeys or only for backlight) is present. Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com> Signed-off-by: Matthew Garrett <matthew.garrett@nebula.com>
Diffstat (limited to 'drivers/platform/x86')
-rw-r--r--drivers/platform/x86/msi-wmi.c101
1 files changed, 64 insertions, 37 deletions
diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
index 112ec1488ea8..3a6061985e4d 100644
--- a/drivers/platform/x86/msi-wmi.c
+++ b/drivers/platform/x86/msi-wmi.c
@@ -60,6 +60,8 @@ static struct key_entry msi_wmi_keymap[] = {
60}; 60};
61static ktime_t last_pressed[ARRAY_SIZE(msi_wmi_keymap) - 1]; 61static ktime_t last_pressed[ARRAY_SIZE(msi_wmi_keymap) - 1];
62 62
63static const char *event_wmi_guid;
64
63static struct backlight_device *backlight; 65static struct backlight_device *backlight;
64 66
65static int backlight_map[] = { 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF }; 67static int backlight_map[] = { 0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF };
@@ -184,7 +186,7 @@ static void msi_wmi_notify(u32 value, void *context)
184 186
185 if (key->type == KE_KEY && 187 if (key->type == KE_KEY &&
186 /* Brightness is served via acpi video driver */ 188 /* Brightness is served via acpi video driver */
187 (!acpi_video_backlight_support() || 189 (backlight ||
188 (key->code != MSI_KEY_BRIGHTNESSUP && 190 (key->code != MSI_KEY_BRIGHTNESSUP &&
189 key->code != MSI_KEY_BRIGHTNESSDOWN))) { 191 key->code != MSI_KEY_BRIGHTNESSDOWN))) {
190 pr_debug("Send key: 0x%X - " 192 pr_debug("Send key: 0x%X - "
@@ -202,6 +204,31 @@ msi_wmi_notify_exit:
202 kfree(response.pointer); 204 kfree(response.pointer);
203} 205}
204 206
207static int __init msi_wmi_backlight_setup(void)
208{
209 int err;
210 struct backlight_properties props;
211
212 memset(&props, 0, sizeof(struct backlight_properties));
213 props.type = BACKLIGHT_PLATFORM;
214 props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
215 backlight = backlight_device_register(DRV_NAME, NULL, NULL,
216 &msi_backlight_ops,
217 &props);
218 if (IS_ERR(backlight))
219 return PTR_ERR(backlight);
220
221 err = bl_get(NULL);
222 if (err < 0) {
223 backlight_device_unregister(backlight);
224 return err;
225 }
226
227 backlight->props.brightness = err;
228
229 return 0;
230}
231
205static int __init msi_wmi_input_setup(void) 232static int __init msi_wmi_input_setup(void)
206{ 233{
207 int err; 234 int err;
@@ -238,60 +265,60 @@ static int __init msi_wmi_init(void)
238{ 265{
239 int err; 266 int err;
240 267
241 if (!wmi_has_guid(MSIWMI_EVENT_GUID)) { 268 if (wmi_has_guid(MSIWMI_EVENT_GUID)) {
242 pr_err("This machine doesn't have MSI-hotkeys through WMI\n"); 269 err = msi_wmi_input_setup();
243 return -ENODEV; 270 if (err) {
244 } 271 pr_err("Unable to setup input device\n");
245 err = wmi_install_notify_handler(MSIWMI_EVENT_GUID, 272 return err;
246 msi_wmi_notify, NULL); 273 }
247 if (ACPI_FAILURE(err))
248 return -EINVAL;
249 274
250 err = msi_wmi_input_setup(); 275 err = wmi_install_notify_handler(MSIWMI_EVENT_GUID,
251 if (err) 276 msi_wmi_notify, NULL);
252 goto err_uninstall_notifier; 277 if (ACPI_FAILURE(err)) {
253 278 pr_err("Unable to setup WMI notify handler\n");
254 if (!acpi_video_backlight_support()) {
255 struct backlight_properties props;
256 memset(&props, 0, sizeof(struct backlight_properties));
257 props.type = BACKLIGHT_PLATFORM;
258 props.max_brightness = ARRAY_SIZE(backlight_map) - 1;
259 backlight = backlight_device_register(DRV_NAME, NULL, NULL,
260 &msi_backlight_ops,
261 &props);
262 if (IS_ERR(backlight)) {
263 err = PTR_ERR(backlight);
264 goto err_free_input; 279 goto err_free_input;
265 } 280 }
266 281
267 err = bl_get(NULL); 282 pr_debug("Event handler installed\n");
268 if (err < 0) 283 event_wmi_guid = MSIWMI_EVENT_GUID;
269 goto err_free_backlight; 284 }
285
286 if (wmi_has_guid(MSIWMI_BIOS_GUID) && !acpi_video_backlight_support()) {
287 err = msi_wmi_backlight_setup();
288 if (err) {
289 pr_err("Unable to setup backlight device\n");
290 goto err_uninstall_handler;
291 }
292 pr_debug("Backlight device created\n");
293 }
270 294
271 backlight->props.brightness = err; 295 if (!event_wmi_guid && !backlight) {
296 pr_err("This machine doesn't have neither MSI-hotkeys nor backlight through WMI\n");
297 return -ENODEV;
272 } 298 }
273 pr_debug("Event handler installed\n");
274 299
275 return 0; 300 return 0;
276 301
277err_free_backlight: 302err_uninstall_handler:
278 backlight_device_unregister(backlight); 303 if (event_wmi_guid)
304 wmi_remove_notify_handler(event_wmi_guid);
279err_free_input: 305err_free_input:
280 sparse_keymap_free(msi_wmi_input_dev); 306 if (event_wmi_guid) {
281 input_unregister_device(msi_wmi_input_dev); 307 sparse_keymap_free(msi_wmi_input_dev);
282err_uninstall_notifier: 308 input_unregister_device(msi_wmi_input_dev);
283 wmi_remove_notify_handler(MSIWMI_EVENT_GUID); 309 }
284 return err; 310 return err;
285} 311}
286 312
287static void __exit msi_wmi_exit(void) 313static void __exit msi_wmi_exit(void)
288{ 314{
289 if (wmi_has_guid(MSIWMI_EVENT_GUID)) { 315 if (event_wmi_guid) {
290 wmi_remove_notify_handler(MSIWMI_EVENT_GUID); 316 wmi_remove_notify_handler(event_wmi_guid);
291 sparse_keymap_free(msi_wmi_input_dev); 317 sparse_keymap_free(msi_wmi_input_dev);
292 input_unregister_device(msi_wmi_input_dev); 318 input_unregister_device(msi_wmi_input_dev);
293 backlight_device_unregister(backlight);
294 } 319 }
320 if (backlight)
321 backlight_device_unregister(backlight);
295} 322}
296 323
297module_init(msi_wmi_init); 324module_init(msi_wmi_init);