Add input interface

This commit is contained in:
Jeremy Soller 2020-09-03 11:14:25 -06:00 committed by Jeremy Soller
parent 03aca3da39
commit ce499988e8
1 changed files with 28 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include <linux/hwmon.h> #include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h> #include <linux/hwmon-sysfs.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/input.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/module.h> #include <linux/module.h>
@ -29,6 +30,7 @@ struct system76_data {
struct device *therm; struct device *therm;
union acpi_object *nfan; union acpi_object *nfan;
union acpi_object *ntmp; union acpi_object *ntmp;
struct input_dev *input;
}; };
static const struct acpi_device_id device_ids[] = { static const struct acpi_device_id device_ids[] = {
@ -422,6 +424,14 @@ static const struct hwmon_chip_info thermal_chip_info = {
.info = thermal_channel_info, .info = thermal_channel_info,
}; };
static void input_key(struct system76_data *data, unsigned int code) {
input_report_key(data->input, code, 1);
input_sync(data->input);
input_report_key(data->input, code, 0);
input_sync(data->input);
}
// Handle ACPI notification // Handle ACPI notification
static void system76_notify(struct acpi_device *acpi_dev, u32 event) static void system76_notify(struct acpi_device *acpi_dev, u32 event)
{ {
@ -444,6 +454,9 @@ static void system76_notify(struct acpi_device *acpi_dev, u32 event)
case 0x84: case 0x84:
kb_led_hotkey_color(data); kb_led_hotkey_color(data);
break; break;
case 0x85:
input_key(data, KEY_SCREENLOCK);
break;
} }
} }
@ -504,6 +517,21 @@ static int system76_add(struct acpi_device *acpi_dev)
if (IS_ERR(data->therm)) if (IS_ERR(data->therm))
return PTR_ERR(data->therm); return PTR_ERR(data->therm);
data->input = devm_input_allocate_device(&acpi_dev->dev);
if (!data->input)
return -ENOMEM;
data->input->name = "System76 ACPI Hotkeys";
data->input->phys = "system76_acpi/input0";
data->input->id.bustype = BUS_HOST;
data->input->dev.parent = &acpi_dev->dev;
set_bit(EV_KEY, data->input->evbit);
set_bit(KEY_SCREENLOCK, data->input->keybit);
err = input_register_device(data->input);
if (err) {
input_free_device(data->input);
return err;
}
return 0; return 0;
} }