All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr
@ 2015-02-18 20:53 Bastien Nocera
  2015-02-20  5:28 ` Darren Hart
  0 siblings, 1 reply; 5+ messages in thread
From: Bastien Nocera @ 2015-02-18 20:53 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh, Darren Hart, ibm-acpi-devel,
	platform-driver-x86, linux-kernel, linux-input

Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/platform/x86/thinkpad_acpi.c | 71 +++++++++++++++++++++++++++++++-----
 1 file changed, 62 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index a6dd017..562d958 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2917,6 +2917,59 @@ static void hotkey_wakeup_hotunplug_complete_notify_change(void)
 		     "wakeup_hotunplug_complete");
 }
 
+/* sysfs adaptive kbd mode --------------------------------------------- */
+
+static int adaptive_keyboard_get_mode(void);
+static int adaptive_keyboard_set_mode(int new_mode);
+
+enum ADAPTIVE_KEY_MODE {
+	HOME_MODE,
+	WEB_BROWSER_MODE,
+	WEB_CONFERENCE_MODE,
+	FUNCTION_MODE,
+	LAYFLAT_MODE
+};
+
+static ssize_t adaptive_kbd_mode_show(struct device *dev,
+			   struct device_attribute *attr,
+			   char *buf)
+{
+	u32 current_mode;
+
+	current_mode = adaptive_keyboard_get_mode();
+	if (current_mode < 0)
+		return current_mode;
+
+	return snprintf(buf, PAGE_SIZE, "%d\n", current_mode);
+}
+
+static ssize_t adaptive_kbd_mode_store(struct device *dev,
+			    struct device_attribute *attr,
+			    const char *buf, size_t count)
+{
+	unsigned long t;
+	int res;
+
+	if (parse_strtoul(buf, LAYFLAT_MODE, &t))
+		return -EINVAL;
+
+	res = adaptive_keyboard_set_mode(t);
+	return (res < 0) ? res : count;
+}
+
+static struct device_attribute dev_attr_adaptive_kbd_mode =
+	__ATTR(adaptive_kbd_mode, S_IWUSR | S_IRUGO,
+		adaptive_kbd_mode_show, adaptive_kbd_mode_store);
+
+static struct attribute *adaptive_kbd_attributes[] = {
+	&dev_attr_adaptive_kbd_mode.attr,
+	NULL
+};
+
+static const struct attribute_group adaptive_kbd_attr_group = {
+	.attrs = adaptive_kbd_attributes,
+};
+
 /* --------------------------------------------------------------------- */
 
 static struct attribute *hotkey_attributes[] __initdata = {
@@ -3230,8 +3283,13 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	/* does it have an adaptive keyboard, like
 	 * the Lenovo Carbon X1 2014 (2nd gen) */
 	if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) {
-		if ((hkeyv >> 8) == 2)
+		if ((hkeyv >> 8) == 2) {
 			tp_features.has_adaptive_kbd = true;
+			res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
+					&adaptive_kbd_attr_group);
+			if (res)
+				goto err_exit;
+		}
 	}
 
 	quirks = tpacpi_check_quirks(tpacpi_hotkey_qtable,
@@ -3444,6 +3502,9 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 
 err_exit:
 	delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj);
+	sysfs_remove_group(&tpacpi_pdev->dev.kobj,
+			&adaptive_kbd_attr_group);
+
 	hotkey_dev_attributes = NULL;
 
 	return (res < 0) ? res : 1;
@@ -3456,14 +3517,6 @@ err_exit:
  * Will consider support rest of modes in future.
  *
  */
-enum ADAPTIVE_KEY_MODE {
-	HOME_MODE,
-	WEB_BROWSER_MODE,
-	WEB_CONFERENCE_MODE,
-	FUNCTION_MODE,
-	LAYFLAT_MODE
-};
-
 const int adaptive_keyboard_modes[] = {
 	HOME_MODE,
 /*	WEB_BROWSER_MODE = 2,
-- 
2.1.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr
  2015-02-18 20:53 [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr Bastien Nocera
@ 2015-02-20  5:28 ` Darren Hart
  2015-02-20 14:36   ` Bastien Nocera
  2015-02-23 17:00   ` Henrique de Moraes Holschuh
  0 siblings, 2 replies; 5+ messages in thread
From: Darren Hart @ 2015-02-20  5:28 UTC (permalink / raw)
  To: Bastien Nocera
  Cc: Henrique de Moraes Holschuh, ibm-acpi-devel, platform-driver-x86,
	linux-kernel, linux-input

On Wed, Feb 18, 2015 at 09:53:44PM +0100, Bastien Nocera wrote:

Commit message please.

> Signed-off-by: Bastien Nocera <hadess@hadess.net>
> ---
>  drivers/platform/x86/thinkpad_acpi.c | 71 +++++++++++++++++++++++++++++++-----
>  1 file changed, 62 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> index a6dd017..562d958 100644
> --- a/drivers/platform/x86/thinkpad_acpi.c
> +++ b/drivers/platform/x86/thinkpad_acpi.c

...

> +static struct device_attribute dev_attr_adaptive_kbd_mode =
> +	__ATTR(adaptive_kbd_mode, S_IWUSR | S_IRUGO,
> +		adaptive_kbd_mode_show, adaptive_kbd_mode_store);
> +

Please use DEVICE_ATTR_RW() macros for new sysfs files.

I'd very much like to see a cleanup of the driver to use these as well.

Henrique, your thoughts / preference?

-- 
Darren Hart
Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr
  2015-02-20  5:28 ` Darren Hart
@ 2015-02-20 14:36   ` Bastien Nocera
  2015-02-23 17:00   ` Henrique de Moraes Holschuh
  1 sibling, 0 replies; 5+ messages in thread
From: Bastien Nocera @ 2015-02-20 14:36 UTC (permalink / raw)
  To: Darren Hart
  Cc: Henrique de Moraes Holschuh, ibm-acpi-devel, platform-driver-x86,
	linux-kernel, linux-input

On Thu, 2015-02-19 at 21:28 -0800, Darren Hart wrote:
> On Wed, Feb 18, 2015 at 09:53:44PM +0100, Bastien Nocera wrote:
> 
> Commit message please.

Added.

> > Signed-off-by: Bastien Nocera <hadess@hadess.net>
> > ---
> >  drivers/platform/x86/thinkpad_acpi.c | 71 +++++++++++++++++++++++++++++++-----
> >  1 file changed, 62 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> > index a6dd017..562d958 100644
> > --- a/drivers/platform/x86/thinkpad_acpi.c
> > +++ b/drivers/platform/x86/thinkpad_acpi.c
> 
> ...
> 
> > +static struct device_attribute dev_attr_adaptive_kbd_mode =
> > +	__ATTR(adaptive_kbd_mode, S_IWUSR | S_IRUGO,
> > +		adaptive_kbd_mode_show, adaptive_kbd_mode_store);
> > +
> 
> Please use DEVICE_ATTR_RW() macros for new sysfs files.

Done.

> I'd very much like to see a cleanup of the driver to use these as well.
> 
> Henrique, your thoughts / preference?

Looks easy enough. I'll post the patch with the new series.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr
  2015-02-20  5:28 ` Darren Hart
  2015-02-20 14:36   ` Bastien Nocera
@ 2015-02-23 17:00   ` Henrique de Moraes Holschuh
  2015-02-23 18:18     ` Bastien Nocera
  1 sibling, 1 reply; 5+ messages in thread
From: Henrique de Moraes Holschuh @ 2015-02-23 17:00 UTC (permalink / raw)
  To: Darren Hart, Bastien Nocera
  Cc: ibm-acpi-devel, platform-driver-x86, linux-kernel, linux-input

On Fri, Feb 20, 2015, at 02:28, Darren Hart wrote:
> On Wed, Feb 18, 2015 at 09:53:44PM +0100, Bastien Nocera wrote:
> 
> Commit message please.
> 
> > Signed-off-by: Bastien Nocera <hadess@hadess.net>
> > ---
> >  drivers/platform/x86/thinkpad_acpi.c | 71 +++++++++++++++++++++++++++++++-----
> >  1 file changed, 62 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> > index a6dd017..562d958 100644
> > --- a/drivers/platform/x86/thinkpad_acpi.c
> > +++ b/drivers/platform/x86/thinkpad_acpi.c
> 
> ...
> 
> > +static struct device_attribute dev_attr_adaptive_kbd_mode =
> > +	__ATTR(adaptive_kbd_mode, S_IWUSR | S_IRUGO,
> > +		adaptive_kbd_mode_show, adaptive_kbd_mode_store);
> > +
> 
> Please use DEVICE_ATTR_RW() macros for new sysfs files.
> 
> I'd very much like to see a cleanup of the driver to use these as well.
> 
> Henrique, your thoughts / preference?

Converting to DEVICE_ATTR_RW/RO would be welcome.

-- 
  "One disk to rule them all, One disk to find them. One disk to bring
  them all and in the darkness grind them. In the Land of Redmond
  where the shadows lie." -- The Silicon Valley Tarot
  Henrique Holschuh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr
  2015-02-23 17:00   ` Henrique de Moraes Holschuh
@ 2015-02-23 18:18     ` Bastien Nocera
  0 siblings, 0 replies; 5+ messages in thread
From: Bastien Nocera @ 2015-02-23 18:18 UTC (permalink / raw)
  To: Henrique de Moraes Holschuh
  Cc: Darren Hart, ibm-acpi-devel, platform-driver-x86, linux-kernel,
	linux-input

On Mon, 2015-02-23 at 14:00 -0300, Henrique de Moraes Holschuh wrote:
> On Fri, Feb 20, 2015, at 02:28, Darren Hart wrote:
> > On Wed, Feb 18, 2015 at 09:53:44PM +0100, Bastien Nocera wrote:
> > 
> > Commit message please.
> > 
> > > Signed-off-by: Bastien Nocera <hadess@hadess.net>
> > > ---
> > >  drivers/platform/x86/thinkpad_acpi.c | 71 +++++++++++++++++++++++++++++++-----
> > >  1 file changed, 62 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
> > > index a6dd017..562d958 100644
> > > --- a/drivers/platform/x86/thinkpad_acpi.c
> > > +++ b/drivers/platform/x86/thinkpad_acpi.c
> > 
> > ...
> > 
> > > +static struct device_attribute dev_attr_adaptive_kbd_mode =
> > > +	__ATTR(adaptive_kbd_mode, S_IWUSR | S_IRUGO,
> > > +		adaptive_kbd_mode_show, adaptive_kbd_mode_store);
> > > +
> > 
> > Please use DEVICE_ATTR_RW() macros for new sysfs files.
> > 
> > I'd very much like to see a cleanup of the driver to use these as well.
> > 
> > Henrique, your thoughts / preference?
> 
> Converting to DEVICE_ATTR_RW/RO would be welcome.

I've already sent the new patch for that though...


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-23 18:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 20:53 [PATCH 3/6] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr Bastien Nocera
2015-02-20  5:28 ` Darren Hart
2015-02-20 14:36   ` Bastien Nocera
2015-02-23 17:00   ` Henrique de Moraes Holschuh
2015-02-23 18:18     ` Bastien Nocera

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.