devicetree.vger.kernel.org archive mirror
 help / color / mirror / 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 v4 2/5] Input: atkbd: Expose function row physical map to userspace
Date: Fri, 24 Apr 2020 14:03:16 -0700	[thread overview]
Message-ID: <20200424210316.GI125362@dtor-ws> (raw)
In-Reply-To: <20200328185916.98423-2-rajatja@google.com>

Hi Rajat,

On Sat, Mar 28, 2020 at 11:59:13AM -0700, Rajat Jain wrote:
> Certain keyboards have their top-row keys intended
> for actions such as "Browser back", "Browser Refresh", "Fullscreen"
> etc as their primary mode, thus they will send physical codes for those
> actions. Further, they don't have a dedicated "Fn" key so don't have
> the capability to generate function key codes (e.g. F1, F2 etc..).
> However in this case, if userspace still wants to "synthesize" those
> function keys using the top row action keys, it needs to know the
> physical position of the top row keys. (Essentially a mapping between
> usage codes and a physical location in the top row).
> 
> This patch enhances the atkbd driver to receive such a mapping from the
> firmware / device tree, and expose it to userspace in the form of
> a function-row-physmap attribute. The attribute would be a space
> separated ordered list of physical codes, for the keys in the function
> row, in left-to-right order.
> 
> The attribute will only be present if the kernel knows about such
> mapping, otherwise the attribute shall not be visible.
> 
> Signed-off-by: Rajat Jain <rajatja@google.com>
> ---
> v4: Same as v3
> v3: Change to dev_dbg and remove unecessary error check
> v2: Remove the Change-Id from the commit log
> 
>  drivers/input/keyboard/atkbd.c | 56 ++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
> 
> diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
> index 7e3eae54c1926..3b20aba1861cd 100644
> --- a/drivers/input/keyboard/atkbd.c
> +++ b/drivers/input/keyboard/atkbd.c
> @@ -24,6 +24,7 @@
>  #include <linux/libps2.h>
>  #include <linux/mutex.h>
>  #include <linux/dmi.h>
> +#include <linux/property.h>
>  
>  #define DRIVER_DESC	"AT and PS/2 keyboard driver"
>  
> @@ -63,6 +64,8 @@ static bool atkbd_terminal;
>  module_param_named(terminal, atkbd_terminal, bool, 0);
>  MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2");
>  
> +#define MAX_FUNCTION_ROW_KEYS	24
> +
>  /*
>   * Scancode to keycode tables. These are just the default setting, and
>   * are loadable via a userland utility.
> @@ -230,6 +233,9 @@ struct atkbd {
>  
>  	/* Serializes reconnect(), attr->set() and event work */
>  	struct mutex mutex;
> +
> +	u16 function_row_physmap[MAX_FUNCTION_ROW_KEYS];
> +	int num_function_row_keys;
>  };
>  
>  /*
> @@ -283,6 +289,7 @@ static struct device_attribute atkbd_attr_##_name =				\
>  	__ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL);
>  
>  ATKBD_DEFINE_RO_ATTR(err_count);
> +ATKBD_DEFINE_RO_ATTR(function_row_physmap);
>  
>  static struct attribute *atkbd_attributes[] = {
>  	&atkbd_attr_extra.attr,
> @@ -292,11 +299,42 @@ static struct attribute *atkbd_attributes[] = {
>  	&atkbd_attr_softrepeat.attr,
>  	&atkbd_attr_softraw.attr,
>  	&atkbd_attr_err_count.attr,
> +	&atkbd_attr_function_row_physmap.attr,
>  	NULL
>  };
>  
> +static ssize_t atkbd_show_function_row_physmap(struct atkbd *atkbd, char *buf)
> +{
> +	ssize_t size = 0;
> +	int i;
> +
> +	if (!atkbd->num_function_row_keys)
> +		return 0;
> +
> +	for (i = 0; i < atkbd->num_function_row_keys; i++)
> +		size += sprintf(buf + size, "%02X ",
> +				atkbd->function_row_physmap[i]);
> +	size += sprintf(buf + size, "\n");

Can we change this to scnprintf() with PAGE_SIZE as the initial limit?

> +	return size;
> +}
> +
> +static umode_t atkbd_attr_is_visible(struct kobject *kobj,
> +				struct attribute *attr, int i)
> +{
> +	struct device *dev = container_of(kobj, struct device, kobj);
> +	struct serio *serio = to_serio_port(dev);
> +	struct atkbd *atkbd = serio_get_drvdata(serio);
> +
> +	if (attr == &atkbd_attr_function_row_physmap.attr &&
> +	    !atkbd->num_function_row_keys)
> +		return 0;
> +
> +	return attr->mode;
> +}
> +
>  static struct attribute_group atkbd_attribute_group = {
>  	.attrs	= atkbd_attributes,
> +	.is_visible = atkbd_attr_is_visible,
>  };
>  
>  static const unsigned int xl_table[] = {
> @@ -1121,6 +1159,22 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd)
>  	}
>  }
>  
> +static void atkbd_parse_fwnode_data(struct serio *serio)
> +{
> +	struct atkbd *atkbd = serio_get_drvdata(serio);
> +	struct device *dev = &serio->dev;
> +	int n;
> +
> +	/* Parse "function-row-physmap" property */
> +	n = device_property_count_u16(dev, "function-row-physmap");

I think for ACPI case it does not matter, but if we ever have device
tree using it, it will lead to less errors if we use u32 as the element
size. Do you mind switching to it?

> +	if (n > 0 && n <= MAX_FUNCTION_ROW_KEYS &&
> +	    !device_property_read_u16_array(dev, "function-row-physmap",
> +					    atkbd->function_row_physmap, n)) {
> +		atkbd->num_function_row_keys = n;
> +		dev_dbg(dev, "FW reported %d function-row key locations\n", n);
> +	}
> +}
> +
>  /*
>   * atkbd_connect() is called when the serio module finds an interface
>   * that isn't handled yet by an appropriate device driver. We check if
> @@ -1184,6 +1238,8 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
>  		atkbd->id = 0xab00;
>  	}
>  
> +	atkbd_parse_fwnode_data(serio);
> +
>  	atkbd_set_keycode_table(atkbd);
>  	atkbd_set_device_attrs(atkbd);
>  

Thanks.

-- 
Dmitry

  reply	other threads:[~2020-04-24 21:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-28 18:59 [PATCH v4 1/5] input/serio/i8042: Attach fwnode to serio i8042 kbd device Rajat Jain
2020-03-28 18:59 ` [PATCH v4 2/5] Input: atkbd: Expose function row physical map to userspace Rajat Jain
2020-04-24 21:03   ` Dmitry Torokhov [this message]
2020-04-27 21:04     ` Rajat Jain
2020-03-28 18:59 ` [PATCH v4 3/5] dt-bindings: input/atkbd.txt: Add binding for "function-row-physmap" Rajat Jain
2020-04-10 16:41   ` Rob Herring
2020-04-24 19:41     ` Rajat Jain
2020-03-28 18:59 ` [PATCH v4 4/5] Input: atkbd: Receive and use physcode->keycode mapping from FW Rajat Jain
2020-03-28 18:59 ` [PATCH v4 5/5] dt-bindings: input/atkbd.txt: Add binding info for "keymap" property Rajat Jain

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=20200424210316.GI125362@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
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).