Linux Input Archive on lore.kernel.org
 help / color / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Rajat Jain <rajatja@google.com>
Cc: dtor@google.com, Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Kate Stewart <kstewart@linuxfoundation.org>,
	Enrico Weigelt <info@metux.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Allison Randal <allison@lohutok.net>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Stephen Boyd <swboyd@chromium.org>,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, furquan@google.com,
	dlaurie@google.com, bleung@google.com, zentaro@google.com,
	dbehr@google.com, rajatxjain@gmail.com
Subject: Re: [PATCH v2 4/5] Input: atkbd: Receive and use physcode->keycode mapping from FW
Date: Thu, 26 Mar 2020 14:20:25 -0700
Message-ID: <20200326212025.GH75430@dtor-ws> (raw)
In-Reply-To: <20200324123518.239768-4-rajatja@google.com>

Hi Rajat,

On Tue, Mar 24, 2020 at 05:35:17AM -0700, Rajat Jain wrote:
> Allow the firmware to specify the mapping between the physical
> code and the linux keycode. This takes the form of a "keymap"
> property which is an array of u32 values, each value specifying
> mapping for a key.
> 
> Signed-off-by: Rajat Jain <rajatja@google.com>
> ---
> v2: Remove the Change-Id from the commit log
> 
>  drivers/input/keyboard/atkbd.c | 39 ++++++++++++++++++++++++++++++++--
>  1 file changed, 37 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> index 7623eebef2593..c8017a5707581 100644
> --- a/drivers/input/keyboard/atkbd.c
> +++ b/drivers/input/keyboard/atkbd.c
> @@ -66,6 +66,9 @@ MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard conne
>  
>  #define MAX_FUNCTION_ROW_KEYS	24
>  
> +#define PHYSCODE(keymap)	((keymap >> 16) & 0xFFFF)
> +#define KEYCODE(keymap)		(keymap & 0xFFFF)
> +
>  /*
>   * Scancode to keycode tables. These are just the default setting, and
>   * are loadable via a userland utility.
> @@ -236,6 +239,9 @@ struct atkbd {
>  
>  	u16 function_row_physmap[MAX_FUNCTION_ROW_KEYS];
>  	int num_function_row_keys;
> +
> +	unsigned short fw_keymap[ATKBD_KEYMAP_SIZE];
> +	bool use_fw_keymap;

Why do we need to keep firmware-provided keymap in atkbd instance? It is
not going anywhere and can be accessed via device_property_* API
whenever we decide to refresh the keymap.

>  };
>  
>  /*
> @@ -1045,7 +1051,10 @@ static void atkbd_set_keycode_table(struct atkbd *atkbd)
>  	memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
>  	bitmap_zero(atkbd->force_release_mask, ATKBD_KEYMAP_SIZE);
>  
> -	if (atkbd->translated) {
> +	if (atkbd->use_fw_keymap) {
> +		memcpy(atkbd->keycode, atkbd->fw_keymap,
> +		       sizeof(atkbd->keycode));
> +	} else if (atkbd->translated) {
>  		for (i = 0; i < 128; i++) {
>  			scancode = atkbd_unxlate_table[i];
>  			atkbd->keycode[i] = atkbd_set2_keycode[scancode];
> @@ -1163,7 +1172,9 @@ static void atkbd_parse_fwnode_data(struct serio *serio)
>  {
>  	struct atkbd *atkbd = serio_get_drvdata(serio);
>  	struct device *dev = &serio->dev;
> -	int n;
> +	int i, n;
> +	u32 *ptr;
> +	u16 physcode, keycode;
>  
>  	if (!dev_fwnode(dev))
>  		return;
> @@ -1176,6 +1187,30 @@ static void atkbd_parse_fwnode_data(struct serio *serio)
>  		atkbd->num_function_row_keys = n;
>  		dev_info(dev, "FW reported %d function-row key locations\n", n);
>  	}
> +
> +	/* Parse "keymap" property */
> +	n = device_property_count_u32(dev, "keymap");
> +	if (n > 0 && n <= ATKBD_KEYMAP_SIZE) {
> +
> +		ptr = kcalloc(n, sizeof(u32), GFP_KERNEL);
> +		if (!ptr)
> +			return;
> +
> +		if (device_property_read_u32_array(dev, "keymap", ptr, n)) {
> +			dev_err(dev, "problem parsing FW keymap property\n");
> +			kfree(ptr);
> +			return;
> +		}
> +
> +		for (i = 0; i < n; i++) {
> +			physcode = PHYSCODE(ptr[i]);
> +			keycode = KEYCODE(ptr[i]);
> +			atkbd->fw_keymap[physcode] = keycode;
> +		}
> +		dev_info(dev, "Using FW keymap (%d keys)\n", n);

This should be dev_dbg().

> +		atkbd->use_fw_keymap = true;
> +		kfree(ptr);
> +	}
>  }
>  
>  /*
> -- 
> 2.25.1.696.g5e7596f4ac-goog
> 

Thanks.

-- 
Dmitry

  reply index

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 12:35 [PATCH v2 1/5] input/serio/i8042: Attach fwnode to serio i8042 kbd device Rajat Jain
2020-03-24 12:35 ` [PATCH v2 2/5] Input: atkbd: Expose function row physical map to userspace Rajat Jain
2020-03-26 21:27   ` Dmitry Torokhov
2020-03-26 22:18     ` Rajat Jain
2020-03-24 12:35 ` [PATCH v2 3/5] dt-bindings: input/atkbd.txt: Add binding for "function-row-physmap" Rajat Jain
2020-03-24 12:35 ` [PATCH v2 4/5] Input: atkbd: Receive and use physcode->keycode mapping from FW Rajat Jain
2020-03-26 21:20   ` Dmitry Torokhov [this message]
2020-03-27  1:37     ` Rajat Jain
2020-03-24 12:35 ` [PATCH v2 5/5] dt-bindings: input/atkbd.txt: Add binding info for "keymap" property Rajat Jain
2020-03-26 21:28   ` Dmitry Torokhov
2020-03-26 21:25 ` [PATCH v2 1/5] input/serio/i8042: Attach fwnode to serio i8042 kbd device Dmitry Torokhov

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=20200326212025.GH75430@dtor-ws \
    --to=dmitry.torokhov@gmail.com \
    --cc=allison@lohutok.net \
    --cc=bleung@google.com \
    --cc=dbehr@google.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dlaurie@google.com \
    --cc=dtor@google.com \
    --cc=furquan@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=info@metux.net \
    --cc=kstewart@linuxfoundation.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rajatja@google.com \
    --cc=rajatxjain@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=swboyd@chromium.org \
    --cc=tglx@linutronix.de \
    --cc=zentaro@google.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

Linux Input Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-input/0 linux-input/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-input linux-input/ https://lore.kernel.org/linux-input \
		linux-input@vger.kernel.org
	public-inbox-index linux-input

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-input


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git