platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tim Crawford <tcrawford@system76.com>
To: platform-driver-x86@vger.kernel.org
Cc: productdev@system76.com, Jeremy Soller <jeremy@system76.com>
Subject: [PATCH v2 2/3] platform/x86: system76_acpi: Replace Fn+F2 function for OLED models
Date: Tue, 28 Sep 2021 16:15:28 -0600	[thread overview]
Message-ID: <20210928221529.70176-3-tcrawford@system76.com> (raw)
In-Reply-To: <20210928221529.70176-1-tcrawford@system76.com>

From: Jeremy Soller <jeremy@system76.com>

System76 laptops models with OLED displays do not support the default
Fn+F2 behavior of turning the embedded display on and off. Some models
instead introduce a new notify event that is used to lock the screen so
the OS will put the display in a low power state.

Signed-off-by: Jeremy Soller <jeremy@system76.com>
Signed-off-by: Tim Crawford <tcrawford@system76.com>
---
 drivers/platform/x86/system76_acpi.c | 30 ++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/platform/x86/system76_acpi.c b/drivers/platform/x86/system76_acpi.c
index 11f0e42386ba..e7c86b543930 100644
--- a/drivers/platform/x86/system76_acpi.c
+++ b/drivers/platform/x86/system76_acpi.c
@@ -13,6 +13,7 @@
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
 #include <linux/init.h>
+#include <linux/input.h>
 #include <linux/kernel.h>
 #include <linux/leds.h>
 #include <linux/module.h>
@@ -29,6 +30,7 @@ struct system76_data {
 	struct device *therm;
 	union acpi_object *nfan;
 	union acpi_object *ntmp;
+	struct input_dev *input;
 };
 
 static const struct acpi_device_id device_ids[] = {
@@ -430,6 +432,15 @@ static const struct hwmon_chip_info thermal_chip_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
 static void system76_notify(struct acpi_device *acpi_dev, u32 event)
 {
@@ -452,6 +463,9 @@ static void system76_notify(struct acpi_device *acpi_dev, u32 event)
 	case 0x84:
 		kb_led_hotkey_color(data);
 		break;
+	case 0x85:
+		input_key(data, KEY_SCREENLOCK);
+		break;
 	}
 }
 
@@ -514,6 +528,22 @@ static int system76_add(struct acpi_device *acpi_dev)
 	if (IS_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;
+	input_set_capability(data->input, EV_KEY, KEY_SCREENLOCK);
+
+	err = input_register_device(data->input);
+	if (err) {
+		input_free_device(data->input);
+		return err;
+	}
+
 	return 0;
 }
 
-- 
2.31.1


  parent reply	other threads:[~2021-09-28 22:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-27 21:06 [PATCH 0/3] platform/x86: system76_acpi: Sync DKMS module changes Tim Crawford
2021-09-27 21:06 ` [PATCH 1/3] platform/x86: system76_acpi: Report temperature and fan speed Tim Crawford
2021-09-27 21:06 ` [PATCH 2/3] platform/x86: system76_acpi: Replace Fn+F2 function for OLED models Tim Crawford
2021-09-28 16:40   ` Barnabás Pőcze
2021-09-27 21:06 ` [PATCH 3/3] platform/x86: system76_acpi: Add battery charging thresholds Tim Crawford
2021-09-28 16:38   ` Barnabás Pőcze
2021-09-28 22:15 ` [PATCH v2 0/3] platform/x86: system76_acpi: Sync DKMS module changes Tim Crawford
2021-09-28 22:15   ` [PATCH v2 1/3] platform/x86: system76_acpi: Report temperature and fan speed Tim Crawford
2021-09-28 22:15   ` Tim Crawford [this message]
2021-09-28 22:15   ` [PATCH v2 3/3] platform/x86: system76_acpi: Add battery charging thresholds Tim Crawford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210928221529.70176-3-tcrawford@system76.com \
    --to=tcrawford@system76.com \
    --cc=jeremy@system76.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=productdev@system76.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).