Skip to contentSkip to conversation

Bind RMI4 over SMBus from PS/2

PATCH In review Benjamin Tissoires 2 participants 6 messages Mar 8, 2017 – Mar 13, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover Bind RMI4 over SMBus from PS/2

Hi Dmitry,

This is mostly a resend of the PS/2-SMBus binding (last 3 patches of now 3 years of trial and errors).
I integrated both warnings raised by Coccinelle, and squashed 4/3 into 3/3.

I really would like your opinion on this solution. If we could have a full cycle in linux-next that would be ideal too :)

Cheers,
Benjamin

Benjamin Tissoires (3):
input: serio - allow others to specify a driver for a serio device
Input: synaptics - allocate a Synaptics Intertouch device
Input: add a PS/2 to SMBus platform module

 drivers/input/misc/Kconfig      |  11 ++
 drivers/input/misc/Makefile     |   1 +
 drivers/input/misc/ps2_smbus.c  | 424 ++++++++++++++++++++++++++++++++++++++++
 drivers/input/mouse/synaptics.c | 103 ++++++++++
 drivers/input/mouse/synaptics.h |   1 +
 drivers/input/serio/serio.c     |  20 ++
 include/linux/serio.h           |   5 +
 7 files changed, 565 insertions(+)
 create mode 100644 drivers/input/misc/ps2_smbus.c
Signature · 1 line
2.9.3
#1 lore raw

PATCH v3 1/3 input: serio - allow others to specify a driver for a serio device

The Lenovo Thinkpads use RMI4 over SMBus in addition to PS/2 for their trackpad. The problem is that the device doesn't enumerate itself besides some registers in PS/2.

Once the initial PS/2 initialization has been made, we need a way to unbind psmouse from the touchpad and use a different (dummy) serio driver to not interfere with SMBus.

This patch adds the mechanisms to unbind psmouse and use a different serio driver, driver which can be marked as manual_bind to not be picked up by inadvertence.

---

no changes in v3

new in v2

---
 drivers/input/serio/serio.c | 20 ++++++++++++++++++++
 include/linux/serio.h       |  5 +++++
 2 files changed, 25 insertions(+)
drivers/input/serio/serio.c +20 -0
index 1ca7f55..14cc383 100644
@@ -704,6 +704,23 @@ void serio_reconnect(struct serio *serio)
 }
 EXPORT_SYMBOL(serio_reconnect);
 
+void serio_bind_manual_driver(struct serio *serio, struct serio_driver *drv)
+{
+	mutex_lock(&serio_mutex);
+	serio->manual_bind = true;
+	serio->manual_drv = &drv->driver;
+	mutex_unlock(&serio_mutex);
+	serio_rescan(serio);
+}
+EXPORT_SYMBOL(serio_bind_manual_driver);
+
+void serio_clear_manual_driver(struct serio *serio)
+{
+	serio->manual_bind = false;
+	serio->manual_drv = NULL;
+}
+EXPORT_SYMBOL(serio_clear_manual_driver);
+
 /*
  * Submits register request to kseriod for subsequent execution.
  * Note that port registration is always asynchronous.
@@ -902,6 +919,9 @@ static int serio_bus_match(struct device *dev, struct device_driver *drv)
 	struct serio *serio = to_serio_port(dev);
 	struct serio_driver *serio_drv = to_serio_driver(drv);
 
+	if (serio->manual_drv && serio->manual_drv == drv)
+		return serio_match_port(serio_drv->id_table, serio);
+
 	if (serio->manual_bind || serio_drv->manual_bind)
 		return 0;
 
include/linux/serio.h +5 -0
index c733cff..1a6f4db 100644
@@ -64,6 +64,9 @@ struct serio {
 	 * may get indigestion when exposed to concurrent access (i8042).
 	 */
 	struct mutex *ps2_cmd_mutex;
+
+	/* Used when forcing a driver instead of the default one. */
+	struct device_driver *manual_drv;
 };
 #define to_serio_port(d)	container_of(d, struct serio, dev)
 
@@ -88,6 +91,8 @@ int serio_open(struct serio *serio, struct serio_driver *drv);
 void serio_close(struct serio *serio);
 void serio_rescan(struct serio *serio);
 void serio_reconnect(struct serio *serio);
+void serio_bind_manual_driver(struct serio *serio, struct serio_driver *drv);
+void serio_clear_manual_driver(struct serio *serio);
 irqreturn_t serio_interrupt(struct serio *serio, unsigned char data, unsigned int flags);
 
 void __serio_register_port(struct serio *serio, struct module *owner);
Signature · 1 line
2.9.3
#2 lore raw

PATCH v3 2/3 Input: synaptics - allocate a Synaptics Intertouch device

In reply to Benjamin Tissoires

Most of the Synaptics devices are connected through PS/2 and a different bus (SMBus or HID over I2C).
The secondary bus capability is indicated by the InterTouch bit in extended capability 0x0C.

When we encounter such a device, we can create a platform device with the information gathered through the PS/2 enumeration as some information might be missing through the other bus. Using a platform device allows to not add any dependency on the psmouse driver.

We only enable the InterTouch device to be created for the laptops registered with the top software button property or those we know that are functional.

In the future, we might change the default to always rely on the InterTouch bus. Currently, users can enable/disable the feature with the psmouse parameter synaptics_intertouch.

The SMBus devices keep their PS/2 connection alive. If the initialization process goes too far (psmouse_activate called), the device disconnects from the I2C bus and stays on the PS/2 bus. We need to be sure the psmouse driver will stop communicating with the device (and the pass-through trackstick too). This part is not addressed here but will be in a following patch.

The HID over I2C devices are enumerated through the ACPI DSDT, and their PS/2 device also exports the InterTouch bit in the extended capability 0x0C. However, the firmware keeps its I2C connection open even after going further in the PS/2 initialization. We don't need to take extra precautions with those device, especially because they block their PS/2 communication when HID over I2C is used.

---

changes in v3:
- Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR reported by scripts/coccinelle/api/ptr_ret.cocci

changes in v2:
- do not store the platform device as psmouse will be disconnected to be replaced by a dummy serio driver.

---
 drivers/input/mouse/synaptics.c | 103 ++++++++++++++++++++++++++++++++++++++++
 drivers/input/mouse/synaptics.h |   1 +
 2 files changed, 104 insertions(+)
drivers/input/mouse/synaptics.c +103 -0
index 597ee4b..bb3e2f9 100644
@@ -29,6 +29,8 @@
 #include <linux/input/mt.h>
 #include <linux/serio.h>
 #include <linux/libps2.h>
+#include <linux/platform_device.h>
+#include <linux/rmi.h>
 #include <linux/slab.h>
 #include "psmouse.h"
 #include "synaptics.h"
@@ -70,6 +72,21 @@
 /* maximum ABS_MT_POSITION displacement (in mm) */
 #define DMAX 10
 
+/*
+ * The newest Synaptics device can use a secondary bus (called InterTouch) which
+ * provides a better bandwidth and allow a better control of the touchpads.
+ * This is used to decide if we need to use this bus or not.
+ */
+enum {
+	SYNAPTICS_INTERTOUCH_NOT_SET = -1,
+	SYNAPTICS_INTERTOUCH_OFF,
+	SYNAPTICS_INTERTOUCH_ON,
+};
+
+static int synaptics_intertouch = SYNAPTICS_INTERTOUCH_NOT_SET;
+module_param_named(synaptics_intertouch, synaptics_intertouch, int, 0644);
+MODULE_PARM_DESC(synaptics_intertouch, "Use a secondary bus for the Synaptics device.");
+
 /*****************************************************************************
  *	Stuff we need even when we do not want native Synaptics support
  ****************************************************************************/
@@ -218,6 +235,89 @@ static const char * const forcepad_pnp_ids[] = {
 	NULL
 };
 
+static const char * const smbus_pnp_ids[] = {
+	/* all of the topbuttonpad_pnp_ids are valid, we just add some extras */
+	"LEN0048", /* X1 Carbon 3 */
+	"LEN0046", /* X250 */
+	"LEN004a", /* W541 */
+	"LEN200f", /* T450s */
+};
+
+static int rmi4_id;
+
+static int synaptics_create_intertouch(struct psmouse *psmouse)
+{
+	struct synaptics_data *priv = psmouse->private;
+	struct platform_device_info pdevinfo;
+	struct platform_device *pdev;
+	struct rmi_device_platform_data pdata = {
+		.sensor_pdata = {
+			.sensor_type = rmi_sensor_touchpad,
+			.axis_align.flip_y = true,
+			/* to prevent cursors jumps: */
+			.kernel_tracking = true,
+		},
+		.f30_data = {
+			.buttonpad = SYN_CAP_CLICKPAD(priv->ext_cap_0c),
+			.trackstick_buttons =
+			  !!SYN_CAP_EXT_BUTTONS_STICK(priv->ext_cap_10),
+		},
+	};
+
+	pdata.sensor_pdata.topbuttonpad =
+			psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
+			!SYN_CAP_EXT_BUTTONS_STICK(priv->ext_cap_10);
+
+	memset(&pdevinfo, 0, sizeof(pdevinfo));
+	pdevinfo.name = "rmi4";
+	pdevinfo.id = rmi4_id++;
+	pdevinfo.data = &pdata;
+	pdevinfo.size_data = sizeof(pdata);
+	pdevinfo.parent = &psmouse->ps2dev.serio->dev;
+
+	pdev = platform_device_register_full(&pdevinfo);
+	return PTR_ERR_OR_ZERO(pdev);
+}
+
+static int synaptics_remove_intertouch_device(struct device *dev, void *data)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	if (strncmp("rmi4", dev_name(dev), 4))
+		return 0;
+
+	platform_device_unregister(pdev);
+
+	return 0;
+}
+
+/**
+ * synaptics_setup_intertouch - called once the PS/2 devices are enumerated
+ * and decides to instantiate a SMBus InterTouch device.
+ */
+static void synaptics_setup_intertouch(struct psmouse *psmouse)
+{
+	int ret;
+
+	/* first remove any remnant platform intertouch devices */
+	bus_for_each_dev(&platform_bus_type, NULL, NULL,
+			 synaptics_remove_intertouch_device);
+
+	if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_OFF)
+		return;
+
+	if (synaptics_intertouch == SYNAPTICS_INTERTOUCH_NOT_SET) {
+		if (!psmouse_matches_pnp_id(psmouse, topbuttonpad_pnp_ids) &&
+		    !psmouse_matches_pnp_id(psmouse, smbus_pnp_ids))
+			return;
+	}
+
+	psmouse_info(psmouse, "device also supported by an other bus.\n");
+	ret = synaptics_create_intertouch(psmouse);
+	if (ret)
+		psmouse_info(psmouse,
+			     "unable to create intertouch device.\n");
+}
 /*****************************************************************************
  *	Synaptics communications functions
  ****************************************************************************/
@@ -1546,6 +1646,9 @@ static int __synaptics_init(struct psmouse *psmouse, bool absolute_mode)
 		}
 	}
 
+	if (SYN_CAP_INTERTOUCH(priv->ext_cap_0c))
+		synaptics_setup_intertouch(psmouse);
+
 	return 0;
 
  init_fail:
drivers/input/mouse/synaptics.h +1 -0
index 116ae25..ccbd3c5 100644
@@ -90,6 +90,7 @@
 #define SYN_CAP_ADV_GESTURE(ex0c)	((ex0c) & 0x080000)
 #define SYN_CAP_REDUCED_FILTERING(ex0c)	((ex0c) & 0x000400)
 #define SYN_CAP_IMAGE_SENSOR(ex0c)	((ex0c) & 0x000800)
+#define SYN_CAP_INTERTOUCH(ex0c)	((ex0c) & 0x004000)
 
 /*
  * The following descibes response for the 0x10 query.
Signature · 1 line
2.9.3
#3 lore raw

PATCH v3 3/3 Input: add a PS/2 to SMBus platform module

In reply to Benjamin Tissoires

This driver is a glue between PS/2 devices that enumerate the RMI4 devices and Elan touchpads to the RMI4 (or Elan) SMBus driver.

We use an intermediate platform device to not add a dependency between psmouse and I2C. It also handles the subtleties of going around the serio mutex lock by deferring the i2c creation/destruction in a separate thread.

---

changes in v3:
- integrate the suspend/resume followup patch
- removed the Kconfig dance for RMI4_SMBUS selecting PS2_SMBUS

changes in v2:
- use our own ps2 driver (detach psmouse and reattach ours)

---
 drivers/input/misc/Kconfig     |  11 ++
 drivers/input/misc/Makefile    |   1 +
 drivers/input/misc/ps2_smbus.c | 424 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 436 insertions(+)
 create mode 100644 drivers/input/misc/ps2_smbus.c
drivers/input/misc/Kconfig +11 -0
index 5b6c522..64362ba 100644
@@ -822,4 +822,15 @@ config INPUT_HISI_POWERKEY
 	  To compile this driver as a module, choose M here: the
 	  module will be called hisi_powerkey.
 
+config PS2_SMBUS
+	tristate "Platform Support for PS/2 Nodes also connected over SMBus"
+	depends on I2C
+	help
+	  Say Y here if you want to support RMI4 or Elan devices connected to
+	  an SMB bus but enumerated through PS/2.
+
+	  if unsure, say N.
+	  To compile this driver as a module, choose M here: the module will be
+	  called ps2_smbus.
+
 endif
drivers/input/misc/Makefile +1 -0
index b10523f..59406da 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_INPUT_PCSPKR)		+= pcspkr.o
 obj-$(CONFIG_INPUT_PM8941_PWRKEY)	+= pm8941-pwrkey.o
 obj-$(CONFIG_INPUT_PM8XXX_VIBRATOR)	+= pm8xxx-vibrator.o
 obj-$(CONFIG_INPUT_PMIC8XXX_PWRKEY)	+= pmic8xxx-pwrkey.o
+obj-$(CONFIG_PS2_SMBUS)			+= ps2_smbus.o
 obj-$(CONFIG_INPUT_POWERMATE)		+= powermate.o
 obj-$(CONFIG_INPUT_PWM_BEEPER)		+= pwm-beeper.o
 obj-$(CONFIG_INPUT_RB532_BUTTON)	+= rb532_button.o
drivers/input/misc/ps2_smbus.c new file +424 -0

424 lines not on this page · raw message

Signature · 1 line
2.9.3
#4 lore raw
In reply to Benjamin Tissoires

Hi,

Quoted 7 lines · Benjamin Tissoires

Hi Dmitry,

This is mostly a resend of the PS/2-SMBus binding (last 3 patches of now 3 years
of trial and errors).
I integrated both warnings raised by Coccinelle, and squashed 4/3 into 3/3.

Just want to provide you some quick feedback from the user's perspective...

I tested this patch set on my somewhat hacked together laptop - I have a Lenovo T440p with the touchpad replaced with a "top button pad" from a T450 or similar.

With this patch set (and using the psmouse.synaptics_intertouch=1 option), the touchpad is found and used via RMI4/SMBUS, and the PS2 passthrough to the trackpoint does work. Passing the buttons presses from the top buttons to the trackpoint device doesn't work - my understanding is the code for this isn't included here?

The touchpad cursor movement (and scrolling, etc.) is so much smoother than with the PS2 interface of this touchpad model... I'm glad these patches are getting closer to complete!

Calvin.

[   17.665070] psmouse serio1: synaptics: queried max coordinates: x [..5676], y [..4758]
[   17.698107] psmouse serio1: synaptics: queried min coordinates: x [1266..], y [1096..]
[   17.760612] psmouse serio1: synaptics: Touchpad model: 1, fw: 8.1, id: 0x1e2b1, caps: 0xf003a3/0x943300/0x12e800/0x10000, board id: 3053, fw id: 2560 [   17.763619] psmouse serio1: synaptics: serio: Synaptics pass-through port at isa0060/serio1/input0
[   17.766577] psmouse serio1: synaptics: device also supported by an other bus.
[   17.807548] input: SynPS/2 Synaptics TouchPad as /devices/platform/i8042/serio1/input/input9
[   18.435205] psmouse serio2: trackpoint: IBM TrackPoint firmware: 0x0e, buttons: 3/3
[   18.630809] input: TPPS/2 IBM TrackPoint as /devices/platform/i8042/serio1/serio2/input/input18
[   19.064659] rmi4_f01 rmi4-00.fn01: found RMI device, manufacturer: Synaptics, product: TM3053-003, fw id: 1741108
[   19.131839] input: Synaptics TM3053-003 as /devices/rmi4-00/input/input19
[   19.152671] rmi4_smbus 9-002c: registered rmi smb driver at 0x2c.
[   20.425233] psmouse serio3: trackpoint: IBM TrackPoint firmware: 0x0e, buttons: 3/3
[   20.482937] input: TPPS/2 IBM TrackPoint as /devices/rmi4-00/rmi4-00.fn03/serio3/input/input21

Signature · 1 line
Calvin Walton <[email protected]>
#5 lore raw

Hi,

Quoted 18 lines · Calvin Walton

Hi,

Quoted 7 lines · Benjamin Tissoires

Hi Dmitry,

This is mostly a resend of the PS/2-SMBus binding (last 3 patches of now 3 years
of trial and errors).
I integrated both warnings raised by Coccinelle, and squashed 4/3 into 3/3.

Just want to provide you some quick feedback from the user's perspective...

I tested this patch set on my somewhat hacked together laptop - I have a Lenovo T440p with the touchpad replaced with a "top button pad" from a T450 or similar.

Quoted 5 lines

With this patch set (and using the psmouse.synaptics_intertouch=1 option), the touchpad is found and used via RMI4/SMBUS, and the PS2 passthrough to the trackpoint does work. Passing the buttons presses from the top buttons to the trackpoint device doesn't work - my understanding is the code for this isn't included here?

You will need a v4.11-rc1 at least for those buttons to be reported.

Quoted 4 lines

The touchpad cursor movement (and scrolling, etc.) is so much smoother than with the PS2 interface of this touchpad model... I'm glad these patches are getting closer to complete!

Dmitry made a respin of them with a saner approach. Unfortunately, the touchpad doesn't respond correctly when psmouse is compiled in the bzImage, so I am still investigating that. So we are hopefully going to see this merged soon. (Looking at your dmesg let me think that psmouse is compiled at a separate module in your case, feel free to test the new series: http://www.spinics.net/lists/linux-input/msg50162.html )

Cheers,
Benjamin

Quoted 18 lines

Calvin.

[   17.665070] psmouse serio1: synaptics: queried max coordinates: x [..5676], y [..4758]
[   17.698107] psmouse serio1: synaptics: queried min coordinates: x [1266..], y [1096..]
[   17.760612] psmouse serio1: synaptics: Touchpad model: 1, fw: 8.1, id: 0x1e2b1, caps: 0xf003a3/0x943300/0x12e800/0x10000, board id: 3053, fw id: 2560 [   17.763619] psmouse serio1: synaptics: serio: Synaptics pass-through port at isa0060/serio1/input0
[   17.766577] psmouse serio1: synaptics: device also supported by an other bus.
[   17.807548] input: SynPS/2 Synaptics TouchPad as /devices/platform/i8042/serio1/input/input9
[   18.435205] psmouse serio2: trackpoint: IBM TrackPoint firmware: 0x0e, buttons: 3/3
[   18.630809] input: TPPS/2 IBM TrackPoint as /devices/platform/i8042/serio1/serio2/input/input18
[   19.064659] rmi4_f01 rmi4-00.fn01: found RMI device, manufacturer: Synaptics, product: TM3053-003, fw id: 1741108
[   19.131839] input: Synaptics TM3053-003 as /devices/rmi4-00/input/input19
[   19.152671] rmi4_smbus 9-002c: registered rmi smb driver at 0x2c.
[   20.425233] psmouse serio3: trackpoint: IBM TrackPoint firmware: 0x0e, buttons: 3/3
[   20.482937] input: TPPS/2 IBM TrackPoint as /devices/rmi4-00/rmi4-00.fn03/serio3/input/input21

Signature · 1 line
Calvin Walton <[email protected]>