Re: [PATCH v9 2/2] Input: synaptics-rmi4 - add SMBus support

2016-06-24 Thread kbuild test robot
Hi,

[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on v4.7-rc4 next-20160624]
[cannot apply to input/next]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Benjamin-Tissoires/i2c-i801-add-support-of-Host-Notify/20160624-224821
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux i2c/for-next


coccinelle warnings: (new ones prefixed by >>)

>> drivers/input/rmi4/rmi_smbus.c:448:3-8: No need to set .owner here. The core 
>> will do it.

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


Re: [PATCH v9 2/2] Input: synaptics-rmi4 - add SMBus support

2016-06-24 Thread kbuild test robot
Hi,

[auto build test WARNING on wsa/i2c/for-next]
[also build test WARNING on v4.7-rc4 next-20160624]
[cannot apply to input/next]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Benjamin-Tissoires/i2c-i801-add-support-of-Host-Notify/20160624-224821
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux i2c/for-next


coccinelle warnings: (new ones prefixed by >>)

>> drivers/input/rmi4/rmi_smbus.c:448:3-8: No need to set .owner here. The core 
>> will do it.

Please review and possibly fold the followup patch.

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


[PATCH v9 2/2] Input: synaptics-rmi4 - add SMBus support

2016-06-24 Thread Benjamin Tissoires
Code 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.

Signed-off-by: Benjamin Tissoires 
Signed-off-by: Andrew Duggan 
---

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

no changes in v8

changes in v8:
- fixes from Dmitry: __le16, __maybe_unused and removed forward declaration

 drivers/input/rmi4/Kconfig |  12 ++
 drivers/input/rmi4/Makefile|   1 +
 drivers/input/rmi4/rmi_bus.h   |  12 ++
 drivers/input/rmi4/rmi_smbus.c | 464 +
 4 files changed, 489 insertions(+)
 create mode 100644 drivers/input/rmi4/rmi_smbus.c

diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
index f73df24..86a180b 100644
--- a/drivers/input/rmi4/Kconfig
+++ b/drivers/input/rmi4/Kconfig
@@ -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
diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
index 95c00a7..3c8ebf2 100644
--- a/drivers/input/rmi4/Makefile
+++ b/drivers/input/rmi4/Makefile
@@ -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
diff --git a/drivers/input/rmi4/rmi_bus.h b/drivers/input/rmi4/rmi_bus.h
index 8995798..b7625a9 100644
--- a/drivers/input/rmi4/rmi_bus.h
+++ b/drivers/input/rmi4/rmi_bus.h
@@ -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
diff --git a/drivers/input/rmi4/rmi_smbus.c b/drivers/input/rmi4/rmi_smbus.c
new file mode 100644
index 000..92c6ab1
--- /dev/null
+++ b/drivers/input/rmi4/rmi_smbus.c
@@ -0,0 +1,464 @@
+/*
+ * Copyright (c) 2015 - 2016 Red Hat, Inc
+ * Copyright (c) 2011, 2012 Synaptics Incorporated
+ * Copyright (c) 2011 Unixphere
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "rmi_driver.h"
+
+#define SMB_PROTOCOL_VERSION_ADDRESS   0xfd
+#define SMB_MAX_COUNT  32
+#define RMI_SMB2_MAP_SIZE  8 /* 8 entry of 4 bytes each */
+#define RMI_SMB2_MAP_FLAGS_WE  0x01
+
+struct mapping_table_entry {
+   __le16 rmiaddr;
+   u8 readcount;
+   u8 flags;
+};
+
+struct rmi_smb_xport {
+   struct rmi_transport_dev xport;
+   struct i2c_client *client;
+
+   struct mutex page_mutex;
+   int page;
+   u8 table_index;
+   struct mutex mappingtable_mutex;
+   struct mapping_table_entry mapping_table[RMI_SMB2_MAP_SIZE];
+};
+
+static int rmi_smb_get_version(struct rmi_smb_xport *rmi_smb)
+{
+   struct i2c_client *client = rmi_smb->client;
+   int retval;
+
+   /* Check if for SMBus new version device by reading version byte. */
+   retval = i2c_smbus_read_byte_data(client, SMB_PROTOCOL_VERSION_ADDRESS);
+   if (retval < 0) {
+   dev_err(>dev, "failed to get SMBus version number!\n");
+   return retval;
+   }
+   return retval + 1;
+}
+
+/* SMB block write - wrapper over ic2_smb_write_block */
+static int smb_block_write(struct rmi_transport_dev *xport,
+ u8 commandcode, const void *buf, size_t len)
+{
+   struct rmi_smb_xport *rmi_smb =
+   container_of(xport, struct rmi_smb_xport, xport);
+   struct i2c_client *client = rmi_smb->client;
+   int retval;
+
+   retval = i2c_smbus_write_block_data(client, commandcode, len, buf);
+
+   rmi_dbg(RMI_DEBUG_XPORT, >dev,
+   "wrote %zd bytes at %#04x: %d (%*ph)\n",
+   len, commandcode, retval, (int)len, buf);
+
+   return retval;
+}
+
+/*
+ * The 

[PATCH v9 2/2] Input: synaptics-rmi4 - add SMBus support

2016-06-24 Thread Benjamin Tissoires
Code 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.

Signed-off-by: Benjamin Tissoires 
Signed-off-by: Andrew Duggan 
---

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

no changes in v8

changes in v8:
- fixes from Dmitry: __le16, __maybe_unused and removed forward declaration

 drivers/input/rmi4/Kconfig |  12 ++
 drivers/input/rmi4/Makefile|   1 +
 drivers/input/rmi4/rmi_bus.h   |  12 ++
 drivers/input/rmi4/rmi_smbus.c | 464 +
 4 files changed, 489 insertions(+)
 create mode 100644 drivers/input/rmi4/rmi_smbus.c

diff --git a/drivers/input/rmi4/Kconfig b/drivers/input/rmi4/Kconfig
index f73df24..86a180b 100644
--- a/drivers/input/rmi4/Kconfig
+++ b/drivers/input/rmi4/Kconfig
@@ -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
diff --git a/drivers/input/rmi4/Makefile b/drivers/input/rmi4/Makefile
index 95c00a7..3c8ebf2 100644
--- a/drivers/input/rmi4/Makefile
+++ b/drivers/input/rmi4/Makefile
@@ -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
diff --git a/drivers/input/rmi4/rmi_bus.h b/drivers/input/rmi4/rmi_bus.h
index 8995798..b7625a9 100644
--- a/drivers/input/rmi4/rmi_bus.h
+++ b/drivers/input/rmi4/rmi_bus.h
@@ -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
diff --git a/drivers/input/rmi4/rmi_smbus.c b/drivers/input/rmi4/rmi_smbus.c
new file mode 100644
index 000..92c6ab1
--- /dev/null
+++ b/drivers/input/rmi4/rmi_smbus.c
@@ -0,0 +1,464 @@
+/*
+ * Copyright (c) 2015 - 2016 Red Hat, Inc
+ * Copyright (c) 2011, 2012 Synaptics Incorporated
+ * Copyright (c) 2011 Unixphere
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "rmi_driver.h"
+
+#define SMB_PROTOCOL_VERSION_ADDRESS   0xfd
+#define SMB_MAX_COUNT  32
+#define RMI_SMB2_MAP_SIZE  8 /* 8 entry of 4 bytes each */
+#define RMI_SMB2_MAP_FLAGS_WE  0x01
+
+struct mapping_table_entry {
+   __le16 rmiaddr;
+   u8 readcount;
+   u8 flags;
+};
+
+struct rmi_smb_xport {
+   struct rmi_transport_dev xport;
+   struct i2c_client *client;
+
+   struct mutex page_mutex;
+   int page;
+   u8 table_index;
+   struct mutex mappingtable_mutex;
+   struct mapping_table_entry mapping_table[RMI_SMB2_MAP_SIZE];
+};
+
+static int rmi_smb_get_version(struct rmi_smb_xport *rmi_smb)
+{
+   struct i2c_client *client = rmi_smb->client;
+   int retval;
+
+   /* Check if for SMBus new version device by reading version byte. */
+   retval = i2c_smbus_read_byte_data(client, SMB_PROTOCOL_VERSION_ADDRESS);
+   if (retval < 0) {
+   dev_err(>dev, "failed to get SMBus version number!\n");
+   return retval;
+   }
+   return retval + 1;
+}
+
+/* SMB block write - wrapper over ic2_smb_write_block */
+static int smb_block_write(struct rmi_transport_dev *xport,
+ u8 commandcode, const void *buf, size_t len)
+{
+   struct rmi_smb_xport *rmi_smb =
+   container_of(xport, struct rmi_smb_xport, xport);
+   struct i2c_client *client = rmi_smb->client;
+   int retval;
+
+   retval = i2c_smbus_write_block_data(client, commandcode, len, buf);
+
+   rmi_dbg(RMI_DEBUG_XPORT, >dev,
+   "wrote %zd bytes at %#04x: %d (%*ph)\n",
+   len, commandcode, retval, (int)len, buf);
+
+   return retval;
+}
+
+/*
+ * The function to get command code for smbus operations and keeps