diff mbox

[3/7] thinkpad_acpi: Add adaptive_kbd_mode sysfs attr

Message ID 1424443462.22910.15.camel@hadess.net (mailing list archive)
State New, archived
Headers show

Commit Message

Bastien Nocera Feb. 20, 2015, 2:44 p.m. UTC
Add a sysfs attribute to allow privileged users to change the keyboard
mode. This could be used by desktop environments to change the keyboard
mode depending on the application focused, as the Windows application
does.

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

Comments

Mika Westerberg Feb. 20, 2015, 3:20 p.m. UTC | #1
On Fri, Feb 20, 2015 at 03:44:22PM +0100, Bastien Nocera wrote:
> Add a sysfs attribute to allow privileged users to change the keyboard
> mode. This could be used by desktop environments to change the keyboard
> mode depending on the application focused, as the Windows application
> does.

If you are adding new sysfs attributes, you should document them as well
in Documentation/ABI/*.
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bastien Nocera Feb. 20, 2015, 3:22 p.m. UTC | #2
On Fri, 2015-02-20 at 17:20 +0200, Mika Westerberg wrote:
> On Fri, Feb 20, 2015 at 03:44:22PM +0100, Bastien Nocera wrote:
> > Add a sysfs attribute to allow privileged users to change the keyboard
> > mode. This could be used by desktop environments to change the keyboard
> > mode depending on the application focused, as the Windows application
> > does.
> 
> If you are adding new sysfs attributes, you should document them as well
> in Documentation/ABI/*.

None of the thinkpad_acpi sysfs attributes are documented there, or I'm
missing something obvious.

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mika Westerberg Feb. 20, 2015, 3:27 p.m. UTC | #3
On Fri, Feb 20, 2015 at 04:22:07PM +0100, Bastien Nocera wrote:
> On Fri, 2015-02-20 at 17:20 +0200, Mika Westerberg wrote:
> > On Fri, Feb 20, 2015 at 03:44:22PM +0100, Bastien Nocera wrote:
> > > Add a sysfs attribute to allow privileged users to change the keyboard
> > > mode. This could be used by desktop environments to change the keyboard
> > > mode depending on the application focused, as the Windows application
> > > does.
> > 
> > If you are adding new sysfs attributes, you should document them as well
> > in Documentation/ABI/*.
> 
> None of the thinkpad_acpi sysfs attributes are documented there, or I'm
> missing something obvious.

Perhaps it is good time to start documenting them? :-)
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bastien Nocera Feb. 20, 2015, 3:31 p.m. UTC | #4
On Fri, 2015-02-20 at 17:27 +0200, Mika Westerberg wrote:
> On Fri, Feb 20, 2015 at 04:22:07PM +0100, Bastien Nocera wrote:
> > On Fri, 2015-02-20 at 17:20 +0200, Mika Westerberg wrote:
> > > On Fri, Feb 20, 2015 at 03:44:22PM +0100, Bastien Nocera wrote:
> > > > Add a sysfs attribute to allow privileged users to change the keyboard
> > > > mode. This could be used by desktop environments to change the keyboard
> > > > mode depending on the application focused, as the Windows application
> > > > does.
> > > 
> > > If you are adding new sysfs attributes, you should document them as well
> > > in Documentation/ABI/*.
> > 
> > None of the thinkpad_acpi sysfs attributes are documented there, or I'm
> > missing something obvious.
> 
> Perhaps it is good time to start documenting them? :-)

I'm not going to do that. If I were, I would remove a large majority of
them to cut down on the size of the driver. 10k lines of code and
supporting 10+ years of ThinkPads turned the driver into a monster.

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Henrique de Moraes Holschuh Feb. 23, 2015, 10:28 a.m. UTC | #5
On Fri, Feb 20, 2015, at 12:20, Mika Westerberg wrote:
> On Fri, Feb 20, 2015 at 03:44:22PM +0100, Bastien Nocera wrote:
> > Add a sysfs attribute to allow privileged users to change the keyboard
> > mode. This could be used by desktop environments to change the keyboard
> > mode depending on the application focused, as the Windows application
> > does.
> 
> If you are adding new sysfs attributes, you should document them as well
> in Documentation/ABI/*.

The thinkpad-acpi driver has its own documentation, it is in
Documentation/laptops/thinkpad-acpi.txt.

The new adaptative keyboard stuff has to be added to it, please.
diff mbox

Patch

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index d395d3f..2030c54 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -2917,6 +2917,57 @@  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 DEVICE_ATTR_RW(adaptive_kbd_mode);
+
+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 = {
@@ -3232,8 +3283,13 @@  static int __init hotkey_init(struct ibm_init_struct *iibm)
 	 * 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,
@@ -3446,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;
@@ -3458,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,