From 3a8d8e44c1b4084c02e8eaf6fd0fb7cd530fdd45 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sat, 29 Oct 2022 00:51:19 +0200
Subject: [PATCH 398/463] input: pinephone-keyboard: Allow to disable Fn layer
 processing

Sometimes it's more flexible to handle Fn key as additional modifier
that can be configured from userspace.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/input/keyboard/pinephone-keyboard.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/input/keyboard/pinephone-keyboard.c b/drivers/input/keyboard/pinephone-keyboard.c
index 365037d8609d1..f758c1eabe40b 100644
--- a/drivers/input/keyboard/pinephone-keyboard.c
+++ b/drivers/input/keyboard/pinephone-keyboard.c
@@ -19,6 +19,10 @@ static bool disable_input;
 module_param(disable_input, bool, S_IRUGO);
 MODULE_PARM_DESC(disable_input, "Disable the keyboard part of the driver");
 
+static bool disable_fn;
+module_param(disable_fn, bool, S_IRUGO);
+MODULE_PARM_DESC(disable_fn, "Disable the FN layer special handling");
+
 #define DRV_NAME			"pinephone-keyboard"
 
 #define PPKB_CRC8_POLYNOMIAL		0x07
@@ -249,6 +253,14 @@ static void ppkb_update(struct i2c_client *client)
 			if (!(changed & mask))
 				continue;
 
+			if (disable_fn) {
+				/* The FN layer is a second set of rows. */
+				code = MATRIX_SCAN_CODE(row, col, row_shift);
+				input_event(ppkb->input, EV_MSC, MSC_SCAN, code);
+				input_report_key(ppkb->input, keymap[code], value);
+				continue;
+			}
+
 			/*
 			 * Save off the FN key state when the key was pressed,
 			 * and use that to determine the code during a release.
-- 
2.46.0

