mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>, linux-input@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	devicetree@vger.kernel.org, linux-i2c@vger.kernel.org,
	Wolfram Sang <wsa@kernel.org>, Ondrej Jirman <x@xff.cz>,
	Samuel Holland <samuel@sholland.org>
Subject: [PATCH 3/5] Input: pinephone-keyboard - Build in the default keymap
Date: Sat, 29 Jan 2022 17:00:40 -0600	[thread overview]
Message-ID: <20220129230043.12422-4-samuel@sholland.org> (raw)
In-Reply-To: <20220129230043.12422-1-samuel@sholland.org>

The PinePhone keyboard comes with removable keys, but there is a default
layout labeled from the factory. Use this keymap if none is provided in
the devicetree.

Suggested-by: Ondrej Jirman <x@xff.cz>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/input/keyboard/pinephone-keyboard.c | 128 +++++++++++++++++++-
 1 file changed, 123 insertions(+), 5 deletions(-)

diff --git a/drivers/input/keyboard/pinephone-keyboard.c b/drivers/input/keyboard/pinephone-keyboard.c
index 9a071753fd91..8065bc3e101a 100644
--- a/drivers/input/keyboard/pinephone-keyboard.c
+++ b/drivers/input/keyboard/pinephone-keyboard.c
@@ -24,6 +24,113 @@
 #define PPKB_SYS_CONFIG			0x20
 #define PPKB_SYS_CONFIG_DISABLE_SCAN		BIT(0)
 
+#define PPKB_DEFAULT_KEYMAP_ROWS	6
+#define PPKB_DEFAULT_KEYMAP_COLS	12
+
+static const uint32_t ppkb_default_fn_keymap[] = {
+	KEY(0,  0, KEY_FN_ESC),
+	KEY(0,  1, KEY_F1),
+	KEY(0,  2, KEY_F2),
+	KEY(0,  3, KEY_F3),
+	KEY(0,  4, KEY_F4),
+	KEY(0,  5, KEY_F5),
+	KEY(0,  6, KEY_F6),
+	KEY(0,  7, KEY_F7),
+	KEY(0,  8, KEY_F8),
+	KEY(0,  9, KEY_F9),
+	KEY(0, 10, KEY_F10),
+	KEY(0, 11, KEY_DELETE),
+
+	KEY(2,  0, KEY_SYSRQ),
+	KEY(2, 10, KEY_INSERT),
+
+	KEY(3,  0, KEY_LEFTSHIFT),
+	KEY(3,  8, KEY_HOME),
+	KEY(3,  9, KEY_UP),
+	KEY(3, 10, KEY_END),
+
+	KEY(4, 1, KEY_LEFTCTRL),
+	KEY(4, 6, KEY_LEFT),
+	KEY(4, 8, KEY_RIGHT),
+	KEY(4, 9, KEY_DOWN),
+
+	KEY(5, 2, KEY_FN),
+	KEY(5, 3, KEY_LEFTALT),
+	KEY(5, 5, KEY_RIGHTALT),
+};
+
+static const struct matrix_keymap_data ppkb_default_fn_keymap_data = {
+	.keymap		= ppkb_default_fn_keymap,
+	.keymap_size	= ARRAY_SIZE(ppkb_default_fn_keymap),
+};
+
+static const uint32_t ppkb_default_keymap[] = {
+	KEY(0,  0, KEY_ESC),
+	KEY(0,  1, KEY_1),
+	KEY(0,  2, KEY_2),
+	KEY(0,  3, KEY_3),
+	KEY(0,  4, KEY_4),
+	KEY(0,  5, KEY_5),
+	KEY(0,  6, KEY_6),
+	KEY(0,  7, KEY_7),
+	KEY(0,  8, KEY_8),
+	KEY(0,  9, KEY_9),
+	KEY(0, 10, KEY_0),
+	KEY(0, 11, KEY_BACKSPACE),
+
+	KEY(1,  0, KEY_TAB),
+	KEY(1,  1, KEY_Q),
+	KEY(1,  2, KEY_W),
+	KEY(1,  3, KEY_E),
+	KEY(1,  4, KEY_R),
+	KEY(1,  5, KEY_T),
+	KEY(1,  6, KEY_Y),
+	KEY(1,  7, KEY_U),
+	KEY(1,  8, KEY_I),
+	KEY(1,  9, KEY_O),
+	KEY(1, 10, KEY_P),
+	KEY(1, 11, KEY_ENTER),
+
+	KEY(2,  0, KEY_LEFTMETA),
+	KEY(2,  1, KEY_A),
+	KEY(2,  2, KEY_S),
+	KEY(2,  3, KEY_D),
+	KEY(2,  4, KEY_F),
+	KEY(2,  5, KEY_G),
+	KEY(2,  6, KEY_H),
+	KEY(2,  7, KEY_J),
+	KEY(2,  8, KEY_K),
+	KEY(2,  9, KEY_L),
+	KEY(2, 10, KEY_SEMICOLON),
+
+	KEY(3,  0, KEY_LEFTSHIFT),
+	KEY(3,  1, KEY_Z),
+	KEY(3,  2, KEY_X),
+	KEY(3,  3, KEY_C),
+	KEY(3,  4, KEY_V),
+	KEY(3,  5, KEY_B),
+	KEY(3,  6, KEY_N),
+	KEY(3,  7, KEY_M),
+	KEY(3,  8, KEY_COMMA),
+	KEY(3,  9, KEY_DOT),
+	KEY(3, 10, KEY_SLASH),
+
+	KEY(4,  1, KEY_LEFTCTRL),
+	KEY(4,  4, KEY_SPACE),
+	KEY(4,  6, KEY_APOSTROPHE),
+	KEY(4,  8, KEY_RIGHTBRACE),
+	KEY(4,  9, KEY_LEFTBRACE),
+
+	KEY(5,  2, KEY_FN),
+	KEY(5,  3, KEY_LEFTALT),
+	KEY(5,  5, KEY_RIGHTALT),
+};
+
+static const struct matrix_keymap_data ppkb_default_keymap_data = {
+	.keymap		= ppkb_default_keymap,
+	.keymap_size	= ARRAY_SIZE(ppkb_default_keymap),
+};
+
 struct pinephone_keyboard {
 	struct input_dev *input;
 	unsigned short *fn_keymap;
@@ -151,6 +258,8 @@ static irqreturn_t ppkb_irq_thread(int irq, void *data)
 
 static int ppkb_probe(struct i2c_client *client)
 {
+	const struct matrix_keymap_data *fn_keymap_data = &ppkb_default_fn_keymap_data;
+	const struct matrix_keymap_data *keymap_data = &ppkb_default_keymap_data;
 	struct device *dev = &client->dev;
 	unsigned int phys_rows, phys_cols;
 	unsigned int map_rows, map_cols;
@@ -176,9 +285,18 @@ static int ppkb_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
-	ret = matrix_keypad_parse_properties(dev, &map_rows, &map_cols);
-	if (ret)
-		return ret;
+	/* Allow the devicetree to override the default keymaps. */
+	if (of_property_read_bool(dev->of_node, "linux,fn-keymap") ||
+	    of_property_read_bool(dev->of_node, "linux,keymap")) {
+		ret = matrix_keypad_parse_properties(dev, &map_rows, &map_cols);
+		if (ret)
+			return ret;
+
+		fn_keymap_data = keymap_data = NULL;
+	} else {
+		map_rows = PPKB_DEFAULT_KEYMAP_ROWS;
+		map_cols = PPKB_DEFAULT_KEYMAP_COLS;
+	}
 
 	phys_rows = info[PPKB_MATRIX_SIZE] & 0xf;
 	phys_cols = info[PPKB_MATRIX_SIZE] >> 4;
@@ -214,14 +332,14 @@ static int ppkb_probe(struct i2c_client *client)
 	__set_bit(EV_MSC, ppkb->input->evbit);
 	__set_bit(EV_REP, ppkb->input->evbit);
 
-	ret = matrix_keypad_build_keymap(NULL, "linux,fn-keymap",
+	ret = matrix_keypad_build_keymap(fn_keymap_data, "linux,fn-keymap",
 					 map_rows, map_cols, NULL, ppkb->input);
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to build FN keymap\n");
 
 	ppkb->fn_keymap = ppkb->input->keycode;
 
-	ret = matrix_keypad_build_keymap(NULL, "linux,keymap",
+	ret = matrix_keypad_build_keymap(keymap_data, "linux,keymap",
 					 map_rows, map_cols, NULL, ppkb->input);
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to build keymap\n");
-- 
2.33.1


  parent reply	other threads:[~2022-01-29 23:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29 23:00 [PATCH 0/5] Pine64 PinePhone keyboard support Samuel Holland
2022-01-29 23:00 ` [PATCH 1/5] dt-bindings: input: Add the PinePhone keyboard binding Samuel Holland
2022-02-11 13:23   ` Rob Herring
2022-02-14  4:41     ` Samuel Holland
2022-01-29 23:00 ` [PATCH 2/5] Input: pinephone-keyboard - Add PinePhone keyboard driver Samuel Holland
2022-02-02  8:07   ` Ondřej Jirman
2022-02-02 11:48   ` Ondřej Jirman
2022-01-29 23:00 ` Samuel Holland [this message]
2022-01-31 19:45   ` [PATCH 3/5] Input: pinephone-keyboard - Build in the default keymap Dmitry Torokhov
2022-02-02  4:58     ` Samuel Holland
2022-05-30  7:05       ` Pavel Machek
2022-04-12 10:20   ` Jarrah
2022-04-12 11:34     ` Ondřej Jirman
2022-01-29 23:00 ` [PATCH 4/5] Input: pinephone-keyboard - Support the proxied I2C bus Samuel Holland
2022-01-30  2:05   ` Ondřej Jirman
2022-01-30  2:43     ` Samuel Holland
2022-01-30  3:00       ` Ondřej Jirman
2022-01-29 23:00 ` [PATCH 5/5] [DO NOT MERGE] arm64: dts: allwinner: pinephone: Add keyboard Samuel Holland

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=20220129230043.12422-4-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=wsa@kernel.org \
    --cc=x@xff.cz \
    /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

all inboxes | Powered by JetHome®