Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * toshiba_wmi.c - Toshiba WMI Hotkey Driver
  3 *
  4 * Copyright (C) 2015 Azael Avalos <coproscefalo@gmail.com>
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License as published by
  8 * the Free Software Foundation; either version 2 of the License, or
  9 * (at your option) any later version.
 10 *
 11 * This program is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License for more details.
 15 *
 16 */
 17
 18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 19
 20#include <linux/kernel.h>
 21#include <linux/module.h>
 22#include <linux/init.h>
 23#include <linux/types.h>
 24#include <linux/acpi.h>
 25#include <linux/input.h>
 26#include <linux/input/sparse-keymap.h>
 
 27
 28MODULE_AUTHOR("Azael Avalos");
 29MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver");
 30MODULE_LICENSE("GPL");
 31
 32#define TOSHIBA_WMI_EVENT_GUID	"59142400-C6A3-40FA-BADB-8A2652834100"
 33
 34MODULE_ALIAS("wmi:"TOSHIBA_WMI_EVENT_GUID);
 35
 36static struct input_dev *toshiba_wmi_input_dev;
 37
 38static const struct key_entry toshiba_wmi_keymap[] __initconst = {
 39	/* TODO: Add keymap values once found... */
 40	/*{ KE_KEY, 0x00, { KEY_ } },*/
 41	{ KE_END, 0 }
 42};
 43
 44static void toshiba_wmi_notify(u32 value, void *context)
 45{
 46	struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
 47	union acpi_object *obj;
 48	acpi_status status;
 49
 50	status = wmi_get_event_data(value, &response);
 51	if (ACPI_FAILURE(status)) {
 52		pr_err("Bad event status 0x%x\n", status);
 53		return;
 54	}
 55
 56	obj = (union acpi_object *)response.pointer;
 57	if (!obj)
 58		return;
 59
 60	/* TODO: Add proper checks once we have data */
 61	pr_debug("Unknown event received, obj type %x\n", obj->type);
 62
 63	kfree(response.pointer);
 64}
 65
 
 
 
 
 
 
 
 
 
 
 66static int __init toshiba_wmi_input_setup(void)
 67{
 68	acpi_status status;
 69	int err;
 70
 71	toshiba_wmi_input_dev = input_allocate_device();
 72	if (!toshiba_wmi_input_dev)
 73		return -ENOMEM;
 74
 75	toshiba_wmi_input_dev->name = "Toshiba WMI hotkeys";
 76	toshiba_wmi_input_dev->phys = "wmi/input0";
 77	toshiba_wmi_input_dev->id.bustype = BUS_HOST;
 78
 79	err = sparse_keymap_setup(toshiba_wmi_input_dev,
 80				  toshiba_wmi_keymap, NULL);
 81	if (err)
 82		goto err_free_dev;
 83
 84	status = wmi_install_notify_handler(TOSHIBA_WMI_EVENT_GUID,
 85					    toshiba_wmi_notify, NULL);
 86	if (ACPI_FAILURE(status)) {
 87		err = -EIO;
 88		goto err_free_keymap;
 89	}
 90
 91	err = input_register_device(toshiba_wmi_input_dev);
 92	if (err)
 93		goto err_remove_notifier;
 94
 95	return 0;
 96
 97 err_remove_notifier:
 98	wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID);
 99 err_free_keymap:
100	sparse_keymap_free(toshiba_wmi_input_dev);
101 err_free_dev:
102	input_free_device(toshiba_wmi_input_dev);
103	return err;
104}
105
106static void toshiba_wmi_input_destroy(void)
107{
108	wmi_remove_notify_handler(TOSHIBA_WMI_EVENT_GUID);
109	sparse_keymap_free(toshiba_wmi_input_dev);
110	input_unregister_device(toshiba_wmi_input_dev);
111}
112
113static int __init toshiba_wmi_init(void)
114{
115	int ret;
116
117	if (!wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
 
118		return -ENODEV;
119
120	ret = toshiba_wmi_input_setup();
121	if (ret) {
122		pr_err("Failed to setup input device\n");
123		return ret;
124	}
125
126	pr_info("Toshiba WMI Hotkey Driver\n");
127
128	return 0;
129}
130
131static void __exit toshiba_wmi_exit(void)
132{
133	if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
134		toshiba_wmi_input_destroy();
135}
136
137module_init(toshiba_wmi_init);
138module_exit(toshiba_wmi_exit);
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * toshiba_wmi.c - Toshiba WMI Hotkey Driver
  4 *
  5 * Copyright (C) 2015 Azael Avalos <coproscefalo@gmail.com>
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  9
 10#include <linux/kernel.h>
 11#include <linux/module.h>
 12#include <linux/init.h>
 13#include <linux/types.h>
 14#include <linux/acpi.h>
 15#include <linux/input.h>
 16#include <linux/input/sparse-keymap.h>
 17#include <linux/dmi.h>
 18
 19MODULE_AUTHOR("Azael Avalos");
 20MODULE_DESCRIPTION("Toshiba WMI Hotkey Driver");
 21MODULE_LICENSE("GPL");
 22
 23#define WMI_EVENT_GUID	"59142400-C6A3-40FA-BADB-8A2652834100"
 24
 25MODULE_ALIAS("wmi:"WMI_EVENT_GUID);
 26
 27static struct input_dev *toshiba_wmi_input_dev;
 28
 29static const struct key_entry toshiba_wmi_keymap[] __initconst = {
 30	/* TODO: Add keymap values once found... */
 31	/*{ KE_KEY, 0x00, { KEY_ } },*/
 32	{ KE_END, 0 }
 33};
 34
 35static void toshiba_wmi_notify(union acpi_object *obj, void *context)
 36{
 
 
 
 
 
 
 
 
 
 
 
 37	if (!obj)
 38		return;
 39
 40	/* TODO: Add proper checks once we have data */
 41	pr_debug("Unknown event received, obj type %x\n", obj->type);
 
 
 42}
 43
 44static const struct dmi_system_id toshiba_wmi_dmi_table[] __initconst = {
 45	{
 46		.ident = "Toshiba laptop",
 47		.matches = {
 48			DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
 49		},
 50	},
 51	{}
 52};
 53
 54static int __init toshiba_wmi_input_setup(void)
 55{
 56	acpi_status status;
 57	int err;
 58
 59	toshiba_wmi_input_dev = input_allocate_device();
 60	if (!toshiba_wmi_input_dev)
 61		return -ENOMEM;
 62
 63	toshiba_wmi_input_dev->name = "Toshiba WMI hotkeys";
 64	toshiba_wmi_input_dev->phys = "wmi/input0";
 65	toshiba_wmi_input_dev->id.bustype = BUS_HOST;
 66
 67	err = sparse_keymap_setup(toshiba_wmi_input_dev,
 68				  toshiba_wmi_keymap, NULL);
 69	if (err)
 70		goto err_free_dev;
 71
 72	status = wmi_install_notify_handler(WMI_EVENT_GUID,
 73					    toshiba_wmi_notify, NULL);
 74	if (ACPI_FAILURE(status)) {
 75		err = -EIO;
 76		goto err_free_dev;
 77	}
 78
 79	err = input_register_device(toshiba_wmi_input_dev);
 80	if (err)
 81		goto err_remove_notifier;
 82
 83	return 0;
 84
 85 err_remove_notifier:
 86	wmi_remove_notify_handler(WMI_EVENT_GUID);
 
 
 87 err_free_dev:
 88	input_free_device(toshiba_wmi_input_dev);
 89	return err;
 90}
 91
 92static void toshiba_wmi_input_destroy(void)
 93{
 94	wmi_remove_notify_handler(WMI_EVENT_GUID);
 
 95	input_unregister_device(toshiba_wmi_input_dev);
 96}
 97
 98static int __init toshiba_wmi_init(void)
 99{
100	int ret;
101
102	if (!wmi_has_guid(WMI_EVENT_GUID) ||
103	    !dmi_check_system(toshiba_wmi_dmi_table))
104		return -ENODEV;
105
106	ret = toshiba_wmi_input_setup();
107	if (ret) {
108		pr_err("Failed to setup input device\n");
109		return ret;
110	}
111
112	pr_info("Toshiba WMI Hotkey Driver\n");
113
114	return 0;
115}
116
117static void __exit toshiba_wmi_exit(void)
118{
119	if (wmi_has_guid(WMI_EVENT_GUID))
120		toshiba_wmi_input_destroy();
121}
122
123module_init(toshiba_wmi_init);
124module_exit(toshiba_wmi_exit);