i2c-smbus: add support for HOST NOTIFY
Subsystems (8)
v7 cover i2c-smbus: add support for HOST NOTIFY
Hi,
this is mostly a resubmission of the v6 with the acks, tested-by and few typos here and there.
We really need this to be integrated in the kernel to be able to finally support the touchpads found in many laptops (such as the Lenovo Thinkpad series, some HPs, and probably many others). Currently those laptops are running the fallback mechanism over PS/2 which is full of bugs as it has not been given the same QA than the RMI4 over SMBus (Windows uses RMI4 over SMBus).
RMI4 is now in Linus' tree since v4.6, so it would be nice to see Host Notify in the I2C tree as well.
Cheers,
Benjamin
Benjamin Tissoires (4):
i2c: add a protocol parameter to the alert callback
i2c-smbus: add SMBus Host Notify support
i2c: i801: add support of Host Notify
Input: synaptics-rmi4 - add SMBus support
Documentation/i2c/smbus-protocol | 3 + drivers/char/ipmi/ipmi_ssif.c | 6 +- drivers/hwmon/lm90.c | 6 +- drivers/i2c/busses/Kconfig | 1 + drivers/i2c/busses/i2c-i801.c | 85 ++++++- drivers/i2c/i2c-smbus.c | 112 +++++++++- drivers/input/rmi4/Kconfig | 12 + drivers/input/rmi4/Makefile | 1 + drivers/input/rmi4/rmi_bus.h | 12 + drivers/input/rmi4/rmi_smbus.c | 470 +++++++++++++++++++++++++++++++++++++++ include/linux/i2c-smbus.h | 44 ++++ include/linux/i2c.h | 10 +- include/uapi/linux/i2c.h | 1 + 13 files changed, 753 insertions(+), 10 deletions(-) create mode 100644 drivers/input/rmi4/rmi_smbus.c
Signature · 1 line
2.5.0
PATCH v7 1/4 i2c: add a protocol parameter to the alert callback
.alert() is meant to be generic, but there is currently no way for the device driver to know which protocol generated the alert. Add a parameter in .alert() to help the device driver to understand what is given in data.
This patch is required to have the support of SMBus Host Notify protocol through .alert().
For hwmon:
For IPMI:
---
new in v2
changes in v3:
- added also lm90.c to support the new API
no changes in v4
no changes in v5
changes in v6:
- made sure lm90 also checks for the type of alert first
no changes in v7
drivers/char/ipmi/ipmi_ssif.c | 6 +++++- drivers/hwmon/lm90.c | 6 +++++- drivers/i2c/i2c-smbus.c | 3 ++- include/linux/i2c.h | 7 ++++++- 4 files changed, 18 insertions(+), 4 deletions(-)
drivers/char/ipmi/ipmi_ssif.c +5 -1
@@ -568,12 +568,16 @@ static void retry_timeout(unsigned long data) } -static void ssif_alert (struct i2c_client *client,unsigned int data) +static void ssif_alert (struct i2c_client *client,enum i2c_alert_protocol type, +unsigned int data) {struct ssif_info *ssif_info =i2c_get_clientdata (client);unsigned long oflags, *flags;bool do_get = false; +if (type !=I2C_PROTOCOL_SMBUS_ALERT ) +return ; +ssif_inc_stat (ssif_info, alerts); flags =ipmi_ssif_lock_cond (ssif_info, &oflags);
drivers/hwmon/lm90.c +5 -1
@@ -1624,10 +1624,14 @@ static int lm90_remove(struct i2c_client *client)return 0 ; } -static void lm90_alert (struct i2c_client *client,unsigned int flag) +static void lm90_alert (struct i2c_client *client,enum i2c_alert_protocol type, +unsigned int flag) {u16 alarms; +if (type !=I2C_PROTOCOL_SMBUS_ALERT ) +return ; +if (lm90_is_tripped (client, &alarms)) {/* * Disable ALERT# output, because these chips don't implement
drivers/i2c/i2c-smbus.c +2 -1
@@ -56,7 +56,8 @@ static int smbus_do_alert(struct device *dev, void *addrp)if (client->dev.driver) { driver =to_i2c_driver (client->dev.driver);if (driver->alert) - driver->alert (client, data->flag); + driver->alert (client,I2C_PROTOCOL_SMBUS_ALERT , + data->flag);else dev_warn (&client->dev,"no driver alert()!\n" ); }else
include/linux/i2c.h +6 -1
@@ -126,6 +126,10 @@ i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client, u8 command, u8 length, u8 *values);#endif /* I2C */ +enum i2c_alert_protocol { +I2C_PROTOCOL_SMBUS_ALERT , +}; +/** * struct i2c_driver - represent an I2C device driver * @class: What kind of i2c device we instantiate (for detect)
@@ -181,7 +185,8 @@ struct i2c_driver {* For the SMBus alert protocol, there is a single bit of data passed * as the alert response's low bit ("event flag"). */ -void (*alert)(struct i2c_client *,unsigned int data); +void (*alert)(struct i2c_client *,enum i2c_alert_protocol protocol, +unsigned int data);/* a ioctl like command that can be used to perform specific functions * with the device.
Signature · 1 line
2.5.0
PATCH v7 2/4 i2c-smbus: add SMBus Host Notify support
In reply to Benjamin TissoiresSMBus Host Notify allows a slave device to act as a master on a bus to notify the host of an interrupt. On Intel chipsets, the functionality is directly implemented in the firmware. We just need to export a function to call .alert() on the proper device driver.
i2c_handle_smbus_host_notify() behaves like i2c_handle_smbus_alert(). When called, it schedules a task that will be able to sleep to go through the list of devices attached to the adapter.
The current implementation allows one Host Notification to be scheduled while an other is running.
---
changes in v2:
- do the actual processing of finding the device in i2c-smbus.c
- remove the i2c-core implementations
- remove the manual toggle of SMBus Host Notify
no changes in v3
changes in v4:
- schedule the worker in i2c_handle_smbus_host_notify() -> it can now be called in an interrupt context.
- introduce i2c_setup_smbus_host_notify()
no changes in v5
changes in v6:
- fix the parameters of the inlined functions when the module is not compiled
changes in v7:
- fixed typo in i2c_handle_smbus_host_notify() warning message ('.' and '\n' were inverted)
Documentation/i2c/smbus-protocol | 3 ++ drivers/i2c/i2c-smbus.c | 113 +++++++++++++++++++++++++++++++++++++-- include/linux/i2c-smbus.h | 44 +++++++++++++++ include/linux/i2c.h | 3 ++ include/uapi/linux/i2c.h | 1 + 5 files changed, 159 insertions(+), 5 deletions(-)
Documentation/i2c/smbus-protocol +3 -0
@@ -199,6 +199,9 @@ alerting device's address. [S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P] +I2C drivers for devices which can trigger SMBus Host Notify should implement +the optional alert() callback. + Packet Error Checking (PEC) ===========================
drivers/i2c/i2c-smbus.c +108 -5
144 lines not on this page · raw message
include/linux/i2c-smbus.h +44 -0
54 lines not on this page · raw message
include/linux/i2c.h +3 -0
@@ -128,6 +128,7 @@ i2c_smbus_read_i2c_block_data_or_emulated(const struct i2c_client *client,enum i2c_alert_protocol {I2C_PROTOCOL_SMBUS_ALERT , +I2C_PROTOCOL_SMBUS_HOST_NOTIFY , };/**
@@ -184,6 +185,8 @@ struct i2c_driver {* The format and meaning of the data value depends on the protocol. * For the SMBus alert protocol, there is a single bit of data passed * as the alert response's low bit ("event flag"). +* For the SMBus Host Notify protocol, the data corresponds to the +* 16-bit payload data reported by the slave device acting as master. */ void (*alert)(struct i2c_client *,enum i2c_alert_protocol protocol,unsigned int data);
include/uapi/linux/i2c.h +1 -0
@@ -101,6 +101,7 @@ struct i2c_msg {#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000/* I2C-like block xfer */ #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000/* w/ 1-byte reg. addr. */ +#define I2C_FUNC_SMBUS_HOST_NOTIFY 0x10000000#define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \ I2C_FUNC_SMBUS_WRITE_BYTE)
Signature · 1 line
2.5.0
PATCH v7 3/4 i2c: i801: add support of Host Notify
In reply to Benjamin TissoiresThe i801 chip can handle the Host Notify feature since ICH 3 as mentioned
in http://www.intel.com/content/dam/doc/datasheet/82801ca-io-controller-hub-3-datasheet.pdf
Enable the functionality unconditionally and propagate the alert on each notification.
With a T440s and a Synaptics touchpad that implements Host Notify, the payload data is always 0x0000, so I am not sure if the device actually sends the payload or if there is a problem regarding the implementation.
---
changes in v2:
- removed the description of the Slave functionality support in the chip table (the table shows what is supported, not what the hardware is capable of)
- use i2c-smbus to forward the notification
- remove the fifo, and directly retrieve the address and payload in the worker
- do not check for Host Notification is the feature is not enabled
- use inw_p() to read the payload instead of 2 inb_p() calls
- add /* fall-through */ comment
- unconditionally enable Host Notify if the hardware supports it (can be disabled by the user)
no changes in v3
changes in v4:
- make use of the new API -> no more worker spawning here
- solved a race between the access of the Host Notify registers and the actual I2C transfers.
changes in v5:
- added SKL Host Notify support
changes in v6:
- select I2C_SMBUS in Kconfig to prevent an undefined reference when I2C_I801 is set to 'Y' while I2C_SMBUS is set to 'M'
no changes in v7
drivers/i2c/busses/Kconfig | 1 + drivers/i2c/busses/i2c-i801.c | 85 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 3 deletions(-)
drivers/i2c/busses/Kconfig +1 -0
@@ -91,6 +91,7 @@ config I2C_I801 tristate "Intel 82801 (ICH/PCH)" depends on PCI select CHECK_SIGNATURE if X86 && DMI + select I2C_SMBUS help If you say yes to this option, support will be included for the Intel 801 family of mainboard I2C interfaces. Specifically, the following
drivers/i2c/busses/i2c-i801.c +82 -3
185 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v7 4/4 Input: synaptics-rmi4 - add SMBus support
In reply to Benjamin TissoiresCode obtained from https://raw.githubusercontent.com/mightybigcar/synaptics-rmi4/jf/drivers/input/rmi4/rmi_smbus.c
and updated to match upstream. And fixed to make it work.
---
new in v5
no changes in v6
changes in v7:
- fixed typos as per Andrew's requests
- changed module author from Allie to Andrew as per Andrew's request
- add suspend/resume callbacks to match upstream rmi4 behavior
drivers/input/rmi4/Kconfig | 12 ++ drivers/input/rmi4/Makefile | 1 + drivers/input/rmi4/rmi_bus.h | 12 ++ drivers/input/rmi4/rmi_smbus.c | 470 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 495 insertions(+) create mode 100644 drivers/input/rmi4/rmi_smbus.c
drivers/input/rmi4/Kconfig +12 -0
@@ -27,6 +27,18 @@ config RMI4_SPI If unsure, say N. +config RMI4_SMB + tristate "RMI4 SMB Support" + depends on RMI4_CORE && I2C + help + Say Y here if you want to support RMI4 devices connected to an SMB + bus. + + If unsure, say N. + + To compile this driver as a module, choose M here: the module will be + called rmi_smbus. + config RMI4_2D_SENSOR bool depends on RMI4_CORE
drivers/input/rmi4/Makefile +1 -0
@@ -11,3 +11,4 @@ rmi_core-$(CONFIG_RMI4_F30) += rmi_f30.o # Transports obj-$(CONFIG_RMI4_I2C) += rmi_i2c.o obj-$(CONFIG_RMI4_SPI) += rmi_spi.o +obj-$(CONFIG_RMI4_SMB) += rmi_smbus.o
drivers/input/rmi4/rmi_bus.h +12 -0
@@ -105,6 +105,18 @@ rmi_get_platform_data(struct rmi_device *d)bool rmi_is_physical_device (struct device *dev);/** +* rmi_reset - reset a RMI4 device +* @d: Pointer to an RMI device +* +* Calls for a reset of each function implemented by a specific device. +* Returns 0 on success or a negative error code. +*/ +static inline int rmi_reset (struct rmi_device *d) +{ +return d->driver->reset_handler (d); +} + +/** * rmi_read - read a single byte * @d: Pointer to an RMI device * @addr: The address to read from
drivers/input/rmi4/rmi_smbus.c new file +470 -0
470 lines not on this page · raw message
Signature · 1 line
2.5.0
Hi Benjamin,
Quoted 2 lines
this is mostly a resubmission of the v6 with the acks, tested-by and few typos here and there.
I actually reviewed v6 but got an NMI so writing the mails fell through the cracks :( Sorry about that! Good news is that the code is fine from my point of view, some documentation updates I'd request. After updating those, I will pick up the core patches right away. Note that while the i801 patch looks good to me, I need Jean's review here. There are other patches pending for i801, that needs to be coordinated by him.
Thanks,
Wolfram
Re: [PATCH v7 1/4] i2c: add a protocol parameter to the alert callback
In reply to Benjamin TissoiresQuoted 9 lines · Benjamin Tissoires
.alert() is meant to be generic, but there is currently no way for the device driver to know which protocol generated the alert. Add a parameter in .alert() to help the device driver to understand what is given in data.
This patch is required to have the support of SMBus Host Notify protocol through .alert().
Tested-by Andrew Duggan <[email protected]
Checkpatch gives an error on this broken email address!
Re: [PATCH v7 2/4] i2c-smbus: add SMBus Host Notify support
In reply to Benjamin TissoiresDocumentation/i2c/smbus-protocol alerting device's address. · line 204
Quoted 11 lines
Documentation/i2c/smbus-protocol +3
-0@@ -199,6 +199,9 @@ alerting device's address. [S] [HostAddr] [Wr] A [DevAddr] A [DataLow] A [DataHigh] A [P] +I2C drivers for devices which can trigger SMBus Host Notify should implement +the optional alert() callback. +
I'd like a similar "This is implemented the following way in the Linux kernel:" paragraph here as in the alert section. The item what bus drivers should do is missing.
Documentation/i2c/smbus-protocol alerting device's address.
Quoted 4 lines
Documentation/i2c/smbus-protocol +4
-0+ if (host_notify->pending) { + spin_unlock_irqrestore(&host_notify->lock, flags); + dev_warn(&adapter->dev, "Host Notify already scheduled.\n"); + return -EFAULT;
Very minor nit: -EBUSY?
Quoted 1 line
+#if
defined(CONFIG_I2C_SMBUS)||defined(CONFIG_I2C_SMBUS_MODULE)
IS_ENABLED()?
Re: [PATCH v7 3/4] i2c: i801: add support of Host Notify
In reply to Benjamin TissoiresQuoted 6 lines · Benjamin Tissoires
The i801 chip can handle the Host Notify feature since ICH 3 as mentioned
in http://www.intel.com/content/dam/doc/datasheet/82801ca-io-controller-hub-3-datasheet.pdfEnable the functionality unconditionally and propagate the alert on each notification.
Quoted 6 lines
With a T440s and a Synaptics touchpad that implements Host Notify, the payload data is always
0x0000, so I am not sure if the device actually sends the payload or if there is a problem regarding the implementation.Tested-by Andrew Duggan <[email protected]>Signed-off-by Benjamin Tissoires <[email protected]>
Did some high level review. Did not dig into datasheets.
Hi Wolfram,
Quoted 9 lines · Wolfram Sang
Hi Benjamin,
Quoted 2 lines
this is mostly a resubmission of the v6 with the acks, tested-by and few typos here and there.
I actually reviewed v6 but got an NMI so writing the mails fell through the cracks :( Sorry about that! Good news is that the code is fine from my point of view, some documentation updates I'd request. After updating those, I will pick up the core patches right away. Note that while the
Great, many thanks!
The documentation fixes look simple enough to do. However, I just realized a conflict in the i801 which requires tests (in the resume call).
Quoted 2 lines
i801 patch looks good to me, I need Jean's review here. There are other patches pending for i801, that needs to be coordinated by him.
OK. I'll try to fetch those pending patches on patchwork and see how the merge would behave.
Cheers,
Benjamin
Quoted 5 lines
Thanks,
Wolfram
Quoted 3 lines
OK. I'll try to fetch those pending patches on patchwork and see how the merge would behave.
Thanks. If you have time for a bit of a reviewing eye on them, this would also be much appreciated :)