diff mbox

[4/5] Input: elantech - provide a sysfs knob for crc_enabled

Message ID 1409407846-15449-5-git-send-email-ulrik.debie-os@e2big.org (mailing list archive)
State New, archived
Headers show

Commit Message

Ulrik De Bie Aug. 30, 2014, 2:10 p.m. UTC
The detection of crc_enabled is known to fail for Fujitsu H730. A DMI
blacklist is added for that, but it can be expected that other laptops
will pop up with this.

Here a sysfs knob is provided to alter the behaviour of crc_enabled.
Writing 0 or 1 to it sets the variable to 0 or 1.
Writing 2 to it will perform the detection and set the variable to 0
or 1 according to the result of the detection.
Reading it will show the crc_enabled variable (0 or 1).

Reported-by: Stefan Valouch <stefan@valouch.com>
Tested-by: Stefan Valouch <stefan@valouch.com>
Tested-by: Alfredo Gemma <alfredo.gemma@gmail.com>
Signed-off-by: Ulrik De Bie <ulrik.debie-os@e2big.org>
---
 drivers/input/mouse/elantech.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Comments

Dmitry Torokhov Nov. 8, 2014, 8:25 a.m. UTC | #1
On Sat, Aug 30, 2014 at 04:10:45PM +0200, Ulrik De Bie wrote:
> The detection of crc_enabled is known to fail for Fujitsu H730. A DMI
> blacklist is added for that, but it can be expected that other laptops
> will pop up with this.
> 
> Here a sysfs knob is provided to alter the behaviour of crc_enabled.
> Writing 0 or 1 to it sets the variable to 0 or 1.
> Writing 2 to it will perform the detection and set the variable to 0
> or 1 according to the result of the detection.
> Reading it will show the crc_enabled variable (0 or 1).
> 

This is over-complicated, please make it straight bool (0/1). If one
wants to redetect it can be done by unbinding and rebinding driver
through sysfs (either at driver level or serio - drvctl attribute -
level).

Thanks.
diff mbox

Patch

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index e86bbd7..c2fb961 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1305,6 +1305,28 @@  static ssize_t elantech_show_int_attr(struct psmouse *psmouse, void *data,
 	return sprintf(buf, "0x%02x\n", (attr->reg && rc) ? -1 : *reg);
 }
 
+
+/*
+ * Write a register value for crc_enabled.
+ * If "2" is given, perform detect again.
+ */
+static ssize_t elantech_set_int_attr_crc_enabled(struct psmouse *psmouse,
+				     void *data, const char *buf, size_t count)
+{
+	struct elantech_data *etd = psmouse->private;
+	unsigned char value;
+	int err;
+
+	err = kstrtou8(buf, 16, &value);
+	if (err)
+		return err;
+
+	etd->crc_enabled = (value == 2) ? elantech_detect_crc_enabled(etd) :
+		value;
+
+	return count;
+}
+
 /*
  * Write a register value by writing a sysfs entry
  */
@@ -1360,6 +1382,19 @@  ELANTECH_INT_ATTR(reg_26, 0x26);
 ELANTECH_INT_ATTR(debug, 0);
 ELANTECH_INT_ATTR(paritycheck, 0);
 
+#define ELANTECH_INT_ATTR_SETFUNCTION(_name, _register, _setfunction)	\
+	static struct elantech_attr_data elantech_attr_##_name = {	\
+		.field_offset = offsetof(struct elantech_data, _name),	\
+		.reg = _register,					\
+	};								\
+	PSMOUSE_DEFINE_ATTR(_name, S_IWUSR | S_IRUGO,			\
+			    &elantech_attr_##_name,			\
+			    elantech_show_int_attr,			\
+			    _setfunction)
+
+ELANTECH_INT_ATTR_SETFUNCTION(crc_enabled, 0,
+	elantech_set_int_attr_crc_enabled);
+
 static struct attribute *elantech_attrs[] = {
 	&psmouse_attr_reg_07.dattr.attr,
 	&psmouse_attr_reg_10.dattr.attr,
@@ -1373,6 +1408,7 @@  static struct attribute *elantech_attrs[] = {
 	&psmouse_attr_reg_26.dattr.attr,
 	&psmouse_attr_debug.dattr.attr,
 	&psmouse_attr_paritycheck.dattr.attr,
+	&psmouse_attr_crc_enabled.dattr.attr,
 	NULL
 };