2015-08-13 19:12:34

by Andrew Duggan

[permalink] [raw]
Subject: [PATCH] Input: synaptics-rmi4: Use generic interrupt handling

Currently the RMI4 driver expects the device to have a GPIO and manages
the that GPIO internally. However, this duplicates functionality which
could be handled by more generic interrupt handling code. Also, some
RMI devices will not have a GPIO or it won't be accessible to the rmi4
driver. This patch removes the GPIO code and instead gets the irq passed
up from the underlying transport (ie i2c-core).

Signed-off-by: Andrew Duggan <[email protected]>
---
Hi Dmitry,

I went ahead and removed the GPIO handling code. If we end up needing GPIO
support in the future it sounds like the right thing go to would be to
reimplement it using the gpiod API.

Thanks,
Andrew

drivers/input/rmi4/rmi_bus.h | 3 ++
drivers/input/rmi4/rmi_driver.c | 81 +++++++----------------------------------
drivers/input/rmi4/rmi_driver.h | 2 -
drivers/input/rmi4/rmi_i2c.c | 27 ++------------
include/linux/rmi.h | 19 ----------
5 files changed, 20 insertions(+), 112 deletions(-)

diff --git a/drivers/input/rmi4/rmi_bus.h b/drivers/input/rmi4/rmi_bus.h
index d4cfc85..4e3bca3 100644
--- a/drivers/input/rmi4/rmi_bus.h
+++ b/drivers/input/rmi4/rmi_bus.h
@@ -175,6 +175,9 @@ struct rmi_transport_dev {
struct device *dev;
struct rmi_device *rmi_dev;

+ int irq;
+ int irq_flags;
+
irqreturn_t (*irq_thread)(int irq, void *p);
irqreturn_t (*hard_irq)(int irq, void *p);

diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index b9db709..585bd7b 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -20,7 +20,6 @@
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/fs.h>
-#include <linux/gpio.h>
#include <linux/kconfig.h>
#include <linux/list.h>
#include <linux/module.h>
@@ -42,27 +41,18 @@

#define DEFAULT_POLL_INTERVAL_MS 13

-#define IRQ_DEBUG(data) (IS_ENABLED(CONFIG_RMI4_DEBUG) && data->irq_debug)
-
static irqreturn_t rmi_irq_thread(int irq, void *p)
{
struct rmi_transport_dev *xport = p;
struct rmi_device *rmi_dev = xport->rmi_dev;
struct rmi_driver *driver = rmi_dev->driver;
- struct rmi_device_platform_data *pdata = xport->dev->platform_data;
struct rmi_driver_data *data;

data = dev_get_drvdata(&rmi_dev->dev);

- if (IRQ_DEBUG(data))
- dev_dbg(xport->dev, "ATTN gpio, value: %d.\n",
- gpio_get_value(pdata->attn_gpio));
-
- if (gpio_get_value(pdata->attn_gpio) == pdata->attn_polarity) {
- data->attn_count++;
- if (driver && driver->irq_handler && rmi_dev)
- driver->irq_handler(rmi_dev, irq);
- }
+ data->attn_count++;
+ if (driver && driver->irq_handler && rmi_dev)
+ driver->irq_handler(rmi_dev, irq);

return IRQ_HANDLED;
}
@@ -124,15 +114,15 @@ static void disable_sensor(struct rmi_device *rmi_dev)
if (!data->enabled)
return;

- if (!data->irq)
+ if (!rmi_dev->xport->irq)
disable_polling(rmi_dev);

if (rmi_dev->xport->ops->disable_device)
rmi_dev->xport->ops->disable_device(rmi_dev->xport);

- if (data->irq) {
- disable_irq(data->irq);
- free_irq(data->irq, rmi_dev->xport);
+ if (rmi_dev->xport->irq > 0) {
+ disable_irq(rmi_dev->xport->irq);
+ free_irq(rmi_dev->xport->irq, rmi_dev->xport);
}

data->enabled = false;
@@ -154,12 +144,12 @@ static int enable_sensor(struct rmi_device *rmi_dev)
}

xport = rmi_dev->xport;
- if (data->irq) {
- retval = request_threaded_irq(data->irq,
+ if (xport->irq > 0) {
+ retval = request_threaded_irq(xport->irq,
xport->hard_irq ? xport->hard_irq : NULL,
xport->irq_thread ?
xport->irq_thread : rmi_irq_thread,
- data->irq_flags,
+ xport->irq_flags,
dev_name(&rmi_dev->dev), xport);
if (retval)
return retval;
@@ -717,15 +707,10 @@ static int rmi_driver_remove(struct device *dev)
{
struct rmi_device *rmi_dev = to_rmi_device(dev);
struct rmi_driver_data *data = dev_get_drvdata(&rmi_dev->dev);
- const struct rmi_device_platform_data *pdata =
- rmi_get_platform_data(rmi_dev);

disable_sensor(rmi_dev);
rmi_free_function_list(rmi_dev);

- if (data->gpio_held)
- gpio_free(pdata->attn_gpio);
-
kfree(data->irq_status);
kfree(data);

@@ -866,47 +851,9 @@ static int rmi_driver_probe(struct device *dev)
mutex_init(&data->suspend_mutex);
}

- if (gpio_is_valid(pdata->attn_gpio)) {
- static const char GPIO_LABEL[] = "attn";
- unsigned long gpio_flags = GPIOF_DIR_IN;
-
- data->irq = gpio_to_irq(pdata->attn_gpio);
- if (pdata->level_triggered) {
- data->irq_flags = IRQF_ONESHOT |
- ((pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH)
- ? IRQF_TRIGGER_HIGH : IRQF_TRIGGER_LOW);
- } else {
- data->irq_flags =
- (pdata->attn_polarity == RMI_ATTN_ACTIVE_HIGH)
- ? IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
- }
-
- if (IS_ENABLED(CONFIG_RMI4_DEV))
- gpio_flags |= GPIOF_EXPORT;
-
- retval = gpio_request_one(pdata->attn_gpio, gpio_flags,
- GPIO_LABEL);
- if (retval) {
- dev_warn(dev, "WARNING: Failed to request ATTN gpio %d, code=%d.\n",
- pdata->attn_gpio, retval);
- retval = 0;
- } else {
- dev_info(dev, "Obtained ATTN gpio %d.\n",
- pdata->attn_gpio);
- data->gpio_held = true;
- if (IS_ENABLED(CONFIG_RMI4_DEV)) {
- retval = gpio_export_link(dev,
- GPIO_LABEL, pdata->attn_gpio);
- if (retval) {
- dev_warn(dev,
- "WARNING: Failed to symlink ATTN gpio!\n");
- retval = 0;
- } else {
- dev_info(dev, "Exported ATTN gpio %d.",
- pdata->attn_gpio);
- }
- }
- }
+ if (rmi_dev->xport->irq > 0) {
+ if (!rmi_dev->xport->hard_irq)
+ rmi_dev->xport->irq_flags = IRQF_ONESHOT;
} else {
data->poll_interval = ktime_set(0,
(pdata->poll_interval_ms ? pdata->poll_interval_ms :
@@ -924,8 +871,6 @@ err_destroy_functions:
rmi_free_function_list(rmi_dev);
kfree(irq_memory);
err_free_mem:
- if (data->gpio_held)
- gpio_free(pdata->attn_gpio);
kfree(data);
return retval < 0 ? retval : 0;
}
diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h
index 34f7a7d..ad69962 100644
--- a/drivers/input/rmi4/rmi_driver.h
+++ b/drivers/input/rmi4/rmi_driver.h
@@ -38,8 +38,6 @@ struct rmi_driver_data {
bool f01_bootloader_mode;

u32 attn_count;
- u32 irq_debug; /* Should be bool, but debugfs wants u32 */
- bool gpio_held;
int irq;
int irq_flags;
int num_of_irq_regs;
diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c
index 24d8a04..cf537c9 100644
--- a/drivers/input/rmi4/rmi_i2c.c
+++ b/drivers/input/rmi4/rmi_i2c.c
@@ -196,9 +196,9 @@ static int rmi_i2c_probe(struct i2c_client *client,
return -EINVAL;
}

- dev_dbg(&client->dev, "Probing %s at %#02x (GPIO %d).\n",
+ dev_dbg(&client->dev, "Probing %s at %#02x.\n",
pdata->sensor_name ? pdata->sensor_name : "-no name-",
- client->addr, pdata->attn_gpio);
+ client->addr);

if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
dev_err(&client->dev,
@@ -206,15 +206,6 @@ static int rmi_i2c_probe(struct i2c_client *client,
return -ENODEV;
}

- if (pdata->gpio_config) {
- retval = pdata->gpio_config(pdata->gpio_data, true);
- if (retval < 0) {
- dev_err(&client->dev, "Failed to configure GPIOs, code: %d.\n",
- retval);
- return retval;
- }
- }
-
rmi_i2c = devm_kzalloc(&client->dev, sizeof(struct rmi_i2c_xport),
GFP_KERNEL);
if (!rmi_i2c)
@@ -226,6 +217,7 @@ static int rmi_i2c_probe(struct i2c_client *client,
rmi_i2c->xport.dev = &client->dev;
rmi_i2c->xport.proto_name = "i2c";
rmi_i2c->xport.ops = &rmi_i2c_ops;
+ rmi_i2c->xport.irq = client->irq;

/*
* Setting the page to zero will (a) make sure the PSR is in a
@@ -241,7 +233,7 @@ static int rmi_i2c_probe(struct i2c_client *client,
if (retval) {
dev_err(&client->dev, "Failed to register transport driver at 0x%.2X.\n",
client->addr);
- goto err_gpio;
+ return retval;
}

i2c_set_clientdata(client, rmi_i2c);
@@ -249,25 +241,14 @@ static int rmi_i2c_probe(struct i2c_client *client,
dev_info(&client->dev, "registered rmi i2c driver at %#04x.\n",
client->addr);
return 0;
-
-err_gpio:
- if (pdata->gpio_config)
- pdata->gpio_config(pdata->gpio_data, false);
-
- return retval;
}

static int rmi_i2c_remove(struct i2c_client *client)
{
- const struct rmi_device_platform_data *pdata =
- dev_get_platdata(&client->dev);
struct rmi_i2c_xport *rmi_i2c = i2c_get_clientdata(client);

rmi_unregister_transport_device(&rmi_i2c->xport);

- if (pdata->gpio_config)
- pdata->gpio_config(pdata->gpio_data, false);
-
return 0;
}

diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index ca35b2f..2f3c79d 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -206,19 +206,6 @@ struct rmi_device_platform_data_spi {
* @firmware_name - if specified will override default firmware name,
* for reflashing.
*
- * @attn_gpio - the index of a GPIO that will be used to provide the ATTN
- * interrupt from the touch sensor.
- * @attn_polarity - indicates whether ATTN is active high or low.
- * @level_triggered - by default, the driver uses edge triggered interrupts.
- * However, this can cause problems with suspend/resume on some platforms. In
- * that case, set this to 1 to use level triggered interrupts.
- * @gpio_config - a routine that will be called when the driver is loaded to
- * perform any platform specific GPIO configuration, and when it is unloaded
- * for GPIO de-configuration. This is typically used to configure the ATTN
- * GPIO and the I2C or SPI pins, if necessary.
- * @gpio_data - platform specific data to be passed to the GPIO configuration
- * function.
- *
* @poll_interval_ms - the time in milliseconds between reads of the interrupt
* status register. This is ignored if attn_gpio is non-zero.
*
@@ -256,12 +243,6 @@ struct rmi_device_platform_data_spi {
struct rmi_device_platform_data {
char *sensor_name; /* Used for diagnostics. */

- int attn_gpio;
- enum rmi_attn_polarity attn_polarity;
- bool level_triggered;
- void *gpio_data;
- int (*gpio_config)(void *gpio_data, bool configure);
-
int poll_interval_ms;

int reset_delay_ms;
--
2.1.4


2015-08-13 19:12:35

by Andrew Duggan

[permalink] [raw]
Subject: [PATCH v2] Input: synaptics-rmi4: Add device tree support for RMI4 I2C devices

Add devicetree binding for I2C devices and add bindings for optional
parameters in the function drivers. Parameters for function drivers are
defined in child nodes for each of the functions.

Signed-off-by: Andrew Duggan <[email protected]>
---
This version depends on the "Use generic interrupt handling" patch so that
it can leverage the generic interrupt bindings.

Thanks,
Andrew

.../devicetree/bindings/input/rmi4/rmi_f01.txt | 37 ++++++
.../devicetree/bindings/input/rmi4/rmi_f11.txt | 54 +++++++++
.../devicetree/bindings/input/rmi4/rmi_i2c.txt | 51 ++++++++
.../devicetree/bindings/vendor-prefixes.txt | 1 +
drivers/input/rmi4/rmi_bus.c | 70 +++++++++++
drivers/input/rmi4/rmi_bus.h | 8 +-
drivers/input/rmi4/rmi_driver.c | 34 +++++-
drivers/input/rmi4/rmi_f01.c | 50 +++++++-
drivers/input/rmi4/rmi_f11.c | 133 ++++++++++++++++++++-
drivers/input/rmi4/rmi_i2c.c | 58 ++++++++-
include/linux/rmi.h | 2 +-
11 files changed, 489 insertions(+), 9 deletions(-)
create mode 100644 Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt
create mode 100644 Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt
create mode 100644 Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt

diff --git a/Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt b/Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt
new file mode 100644
index 0000000..63a1793
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt
@@ -0,0 +1,37 @@
+Synaptics RMI4 F01 Device Binding
+
+The Synaptics RMI4 core is able to support RMI4 devices using differnet
+transports and differnet functions. This file describes the device tree
+bindings for devices which contain Function 1. Complete documentation
+for transports and other functions can be found in:
+Documentation/devicetree/bindings/input/rmi4.
+
+Additional documentation for F01 can be found at:
+http://www.synaptics.com/sites/default/files/511-000136-01-Rev-E-RMI4-Interfacing-Guide.pdf
+
+Optional Properties:
+- syna,nosleep: If set the device will run at full power without sleeping.
+- syna,wakeup-threshold: Defines the amplitude of the disturbance to the
+ background capacitance that will cause the
+ device to wake from dozing.
+- syna,doze-holdoff: The delay to wait after the last finger lift and the
+ first doze cycle (in 0.1 second units).
+- syna,doze-interval: The time period that the device sleeps between finger
+ activity (in 10 ms units).
+
+
+Example of a RMI4 I2C device with F01:
+ Example:
+ &i2c1 {
+ rmi-i2c-dev@2c {
+ compatible = "syna,rmi-i2c";
+
+ ...
+
+ rmi-f01@1 {
+ reg = <0x1>;
+ syna,nosleep = <1>;
+ };
+ };
+ };
+
diff --git a/Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt b/Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt
new file mode 100644
index 0000000..8236a1f
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt
@@ -0,0 +1,54 @@
+Synaptics RMI4 F11 Device Binding
+
+The Synaptics RMI4 core is able to support RMI4 devices using differnet
+transports and differnet functions. This file describes the device tree
+bindings for devices which contain Function 11. Complete documentation
+for transports and other functions can be found in:
+Documentation/devicetree/bindings/input/rmi4.
+
+RMI4 Function 11 is for 2D touch position sensing. Additional documentation for
+F11 can be found at:
+http://www.synaptics.com/sites/default/files/511-000136-01-Rev-E-RMI4-Interfacing-Guide.pdf
+
+Optional Properties:
+- syna,swap-axes: Swap X and Y positions when reporting.
+- syna,flip-x: Reverse the direction of X.
+- syna,flip-y: Reverse the direction of Y.
+- syna,clip-x-low: Sets a minimum value for X.
+- syna,clip-y-low: Sets a minimum value for Y.
+- syna,clip-x-high: Sets a maximum value for X.
+- syna,clip-y-high: Sets a maximum value for Y.
+- syna,offset-x: Add an offset to X.
+- syna,offset_y: Add an offset to Y.
+- syna,delta-x-threshold: Set the minimum distance on the X axis required
+ to generate an interrupt in reduced reporting
+ mode.
+- syna,delta-y-threshold: Set the minimum distance on the Y axis required
+ to generate an interrupt in reduced reporting
+ mode.
+- syna,type-a: Report type A multitouch events.
+- syna,sensor-type: Set the sensor type. 1 for touchscreen 2 for touchpad.
+- syna,x-mm: The length in millimeters of the X axis.
+- syna,y-mm: The length in millimeters of the Y axis.
+- syna,disable-report-mask: Mask for disabling posiiton reporting. Used to
+ disable reporing absolute position data.
+- syna,rezero-wait: Time in miliseconds to wait after issuing a rezero
+ command.
+
+
+Example of a RMI4 I2C device with F11:
+Example:
+ &i2c1 {
+ rmi-i2c-dev@2c {
+ compatible = "syna,rmi-i2c";
+
+ ...
+
+ rmi-f11@11 {
+ reg = <0x11>;
+ syna,flip-y = <1>;
+ syna,sensor-type = <2>;
+ };
+ };
+ };
+
diff --git a/Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt b/Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt
new file mode 100644
index 0000000..e3fcacd
--- /dev/null
+++ b/Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt
@@ -0,0 +1,51 @@
+Synaptics RMI4 I2C Device Binding
+
+The Synaptics RMI4 core is able to support RMI4 devices using differnet
+transports and differnet functions. This file describes the device tree
+bindings for devices using the I2C tranport driver. Complete documentation
+for other transports and functions cen be found ini
+Documentation/devicetree/bindings/input/rmi4.
+
+Required Properties:
+- compatible: syna,rmi-i2c
+- reg: I2C address
+
+Optional Properties:
+- interrupts: interrupt which the rmi device is connected to.
+- interrupt-parent: The interrupt controller.
+See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+
+- syna,sensor-name: The string containing the name of the sensor.
+- syna,poll-interval-ms: The interval in milliseconds to wait between reading
+ interrupts when the driver is polling.
+- syna,reset-delay-ms: The number of milliseconds to wait after resetting the
+ device.
+
+Function Parameters:
+Parameters specific to RMI functions are contained in child nodes of the rmi device
+ node. Documentation for the parameters of each function can be found in:
+Documentation/devicetree/bindings/input/rmi4/rmi_f*.txt.
+
+
+
+Example:
+ &i2c1 {
+ rmi-i2c-dev@2c {
+ compatible = "syna,rmi-i2c";
+ reg = <0x2c>;
+ interrupt-parent = <&gpio>;
+ interrupts = <4 2>;
+ syna,sensor-name="TM1949";
+
+ rmi-f01@1 {
+ reg = <0x1>;
+ syna,f01-nosleep = <1>;
+ };
+
+ rmi-f11@11 {
+ reg = <0x11>;
+ syna,f11-flip-y = <1>;
+ syna,f11-sensor-type = <2>;
+ };
+ };
+ };
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 40ce2df..3ea0a43 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -85,6 +85,7 @@ spansion Spansion Inc.
st STMicroelectronics
ste ST-Ericsson
stericsson ST-Ericsson
+syna Synaptics Inc.
ti Texas Instruments
tlm Trusted Logic Mobility
toshiba Toshiba Corporation
diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index 6e0454a..26f9f17 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.c
@@ -16,6 +16,7 @@
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/debugfs.h>
+#include <linux/of.h>
#include "rmi_bus.h"
#include "rmi_driver.h"

@@ -203,6 +204,21 @@ static int rmi_function_match(struct device *dev, struct device_driver *drv)
return fn->fd.function_number == handler->func;
}

+#ifdef CONFIG_OF
+static void rmi_function_of_probe(struct rmi_function *fn)
+{
+ char of_name[8];
+
+ snprintf(of_name, sizeof(of_name), "rmi-f%02x",
+ fn->fd.function_number);
+ fn->dev.of_node = of_find_node_by_name(
+ fn->rmi_dev->xport->dev->of_node, of_name);
+}
+#else
+static inline void rmi_function_of_probe(struct rmi_function *fn)
+{}
+#endif
+
static int rmi_function_probe(struct device *dev)
{
struct rmi_function *fn = to_rmi_function(dev);
@@ -210,6 +226,8 @@ static int rmi_function_probe(struct device *dev)
to_rmi_function_handler(dev->driver);
int error;

+ rmi_function_of_probe(fn);
+
if (handler->probe) {
error = handler->probe(fn);
return error;
@@ -267,6 +285,10 @@ void rmi_unregister_function(struct rmi_function *fn)
{
device_del(&fn->dev);
rmi_function_teardown_debugfs(fn);
+
+ if (fn->dev.of_node)
+ of_node_put(fn->dev.of_node);
+
put_device(&fn->dev);
}

@@ -335,6 +357,54 @@ struct bus_type rmi_bus_type = {
.name = "rmi",
};

+int rmi_of_property_read_u32(struct device *dev, u32 *result,
+ const char *prop, bool optional)
+{
+ int retval;
+ u32 val = 0;
+
+ retval = of_property_read_u32(dev->of_node, prop, &val);
+ if (retval && (!optional && retval == -EINVAL)) {
+ dev_err(dev, "Failed to get %s value: %d\n",
+ prop, retval);
+ return retval;
+ }
+ *result = val;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(rmi_of_property_read_u32);
+
+int rmi_of_property_read_u16(struct device *dev, u16 *result,
+ const char *prop, bool optional)
+{
+ int retval;
+ u32 val = 0;
+
+ retval = rmi_of_property_read_u32(dev, &val, prop, optional);
+ if (retval)
+ return retval;
+ *result = val;
+
+ return retval;
+}
+EXPORT_SYMBOL_GPL(rmi_of_property_read_u16);
+
+int rmi_of_property_read_u8(struct device *dev, u8 *result,
+ const char *prop, bool optional)
+{
+ int retval;
+ u32 val = 0;
+
+ retval = rmi_of_property_read_u32(dev, &val, prop, optional);
+ if (retval)
+ return retval;
+ *result = val;
+
+ return retval;
+}
+EXPORT_SYMBOL_GPL(rmi_of_property_read_u8);
+
#ifdef CONFIG_RMI4_DEBUG

static void rmi_bus_setup_debugfs(void)
diff --git a/drivers/input/rmi4/rmi_bus.h b/drivers/input/rmi4/rmi_bus.h
index 4e3bca3..2241bd8 100644
--- a/drivers/input/rmi4/rmi_bus.h
+++ b/drivers/input/rmi4/rmi_bus.h
@@ -226,7 +226,7 @@ struct rmi_device {

#define to_rmi_device(d) container_of(d, struct rmi_device, dev)

-static inline const struct rmi_device_platform_data *
+static inline struct rmi_device_platform_data *
rmi_get_platform_data(struct rmi_device *d)
{
return dev_get_platdata(d->xport->dev);
@@ -317,4 +317,10 @@ int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));

extern struct bus_type rmi_bus_type;

+int rmi_of_property_read_u32(struct device *dev, u32 *result,
+ const char *prop, bool optional);
+int rmi_of_property_read_u16(struct device *dev, u16 *result,
+ const char *prop, bool optional);
+int rmi_of_property_read_u8(struct device *dev, u8 *result,
+ const char *prop, bool optional);
#endif
diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
index 585bd7b..67cd7fa 100644
--- a/drivers/input/rmi4/rmi_driver.c
+++ b/drivers/input/rmi4/rmi_driver.c
@@ -717,11 +717,37 @@ static int rmi_driver_remove(struct device *dev)
return 0;
}

+#ifdef CONFIG_OF
+static int rmi_driver_of_probe(struct device *dev,
+ struct rmi_device_platform_data *pdata)
+{
+ int retval;
+
+ retval = rmi_of_property_read_u32(dev, &pdata->poll_interval_ms,
+ "syna,poll-interval-ms", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u32(dev, &pdata->reset_delay_ms,
+ "syna,reset-delay-ms", 1);
+ if (retval)
+ return retval;
+
+ return 0;
+}
+#else
+static inline int rmi_driver_of_probe(struct device *dev,
+ struct rmi_device_platform_data *pdata)
+{
+ return -ENODEV;
+}
+#endif
+
static int rmi_driver_probe(struct device *dev)
{
struct rmi_driver *rmi_driver;
struct rmi_driver_data *data;
- const struct rmi_device_platform_data *pdata;
+ struct rmi_device_platform_data *pdata;
struct rmi_device *rmi_dev;
size_t size;
void *irq_memory;
@@ -741,6 +767,12 @@ static int rmi_driver_probe(struct device *dev)

pdata = rmi_get_platform_data(rmi_dev);

+ if (rmi_dev->xport->dev->of_node) {
+ retval = rmi_driver_of_probe(rmi_dev->xport->dev, pdata);
+ if (retval)
+ return retval;
+ }
+
data = kzalloc(sizeof(struct rmi_driver_data), GFP_KERNEL);
if (!data) {
dev_err(dev, "%s: Failed to allocate driver data.\n", __func__);
diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
index ee5f4a1..9882593 100644
--- a/drivers/input/rmi4/rmi_f01.c
+++ b/drivers/input/rmi4/rmi_f01.c
@@ -12,6 +12,7 @@
#include <linux/rmi.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
+#include <linux/of.h>
#include "rmi_driver.h"

#define RMI_PRODUCT_ID_LENGTH 10
@@ -176,16 +177,63 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
return 0;
}

+#ifdef CONFIG_OF
+static int rmi_f01_of_probe(struct device *dev,
+ struct rmi_device_platform_data *pdata)
+{
+ int retval;
+
+ retval = rmi_of_property_read_u32(dev,
+ (u32 *)&pdata->power_management.nosleep,
+ "syna,nosleep", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u8(dev,
+ &pdata->power_management.wakeup_threshold,
+ "syna,wakeup-threshold", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u8(dev,
+ &pdata->power_management.doze_holdoff,
+ "syna,doze-holdoff", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u8(dev,
+ &pdata->power_management.doze_interval,
+ "syna,doze-interval", 1);
+ if (retval)
+ return retval;
+
+ return 0;
+}
+#else
+static inline int rmi_f01_of_probe(struct device *dev,
+ struct rmi_device_platform_data *pdata)
+{
+ return -ENODEV;
+}
+#endif
+
static int rmi_f01_probe(struct rmi_function *fn)
{
struct rmi_device *rmi_dev = fn->rmi_dev;
struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
- const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
+ struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
struct f01_data *f01;
int error;
u16 ctrl_base_addr = fn->fd.control_base_addr;
u8 device_status;
u8 temp;
+ int retval;
+
+ if (fn->dev.of_node) {
+ retval = rmi_f01_of_probe(&fn->dev, pdata);
+ if (retval)
+ return retval;
+ }

f01 = devm_kzalloc(&fn->dev, sizeof(struct f01_data), GFP_KERNEL);
if (!f01) {
diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c
index 7af4f68..56add28 100644
--- a/drivers/input/rmi4/rmi_f11.c
+++ b/drivers/input/rmi4/rmi_f11.c
@@ -15,6 +15,7 @@
#include <linux/kconfig.h>
#include <linux/rmi.h>
#include <linux/slab.h>
+#include <linux/of.h>
#include "rmi_driver.h"

#define F11_MAX_NUM_OF_FINGERS 10
@@ -1206,6 +1207,124 @@ static void f11_set_abs_params(struct rmi_function *fn, struct f11_data *f11)
0, MT_TOOL_FINGER, 0, 0);
}

+#ifdef CONFIG_OF
+static int rmi_f11_of_initialize(struct device *dev,
+ struct rmi_device_platform_data *pdata)
+{
+ u32 val;
+ int retval;
+
+ retval = rmi_of_property_read_u32(dev,
+ &pdata->f11_sensor_data->axis_align.swap_axes,
+ "syna,swap-axes", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u32(dev,
+ &pdata->f11_sensor_data->axis_align.flip_x,
+ "syna,flip-x", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u32(dev,
+ &pdata->f11_sensor_data->axis_align.flip_y,
+ "syna,flip-y", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u16(dev,
+ &pdata->f11_sensor_data->axis_align.clip_x_low,
+ "syna,clip-x-low", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u16(dev,
+ &pdata->f11_sensor_data->axis_align.clip_y_low,
+ "syna,clip-y-low", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u16(dev,
+ &pdata->f11_sensor_data->axis_align.clip_x_high,
+ "syna,clip-x-high", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u16(dev,
+ &pdata->f11_sensor_data->axis_align.clip_y_high,
+ "syna,clip-y-high", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u16(dev,
+ &pdata->f11_sensor_data->axis_align.offset_x,
+ "syna,offset-x", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u16(dev,
+ &pdata->f11_sensor_data->axis_align.offset_y,
+ "syna,offset_y", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u8(dev,
+ &pdata->f11_sensor_data->axis_align.delta_x_threshold,
+ "syna,delta-x-threshold", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u8(dev,
+ &pdata->f11_sensor_data->axis_align.delta_y_threshold,
+ "syna,delta-y-threshold", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u32(dev, &val,
+ "syna,type-a", 1);
+ if (retval)
+ return retval;
+ pdata->f11_sensor_data->type_a = !!val;
+
+ retval = rmi_of_property_read_u32(dev,
+ (u32 *)&pdata->f11_sensor_data->sensor_type,
+ "syna,sensor-type", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u32(dev,
+ (u32 *)&pdata->f11_sensor_data->x_mm,
+ "syna,x-mm", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u32(dev,
+ (u32 *)&pdata->f11_sensor_data->y_mm,
+ "syna,y-mm", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u32(dev,
+ (u32 *)&pdata->f11_sensor_data->disable_report_mask,
+ "syna,disable-report-mask", 1);
+ if (retval)
+ return retval;
+
+ retval = rmi_of_property_read_u16(dev, &pdata->f11_rezero_wait,
+ "syna,rezero-wait", 1);
+ if (retval)
+ return retval;
+
+ return 0;
+}
+#else
+static inline int rmi_f11_of_initialize(struct device *dev,
+ struct rmi_device_platform_data *pdata)
+{
+ return -ENODEV;
+}
+#endif
+
static int rmi_f11_initialize(struct rmi_function *fn)
{
struct rmi_device *rmi_dev = fn->rmi_dev;
@@ -1216,7 +1335,7 @@ static int rmi_f11_initialize(struct rmi_function *fn)
u16 control_base_addr;
u16 max_x_pos, max_y_pos, temp;
int rc;
- const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
+ struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
struct f11_2d_sensor *sensor;
u8 buf;
@@ -1225,6 +1344,18 @@ static int rmi_f11_initialize(struct rmi_function *fn)
dev_dbg(&fn->dev, "Initializing F11 values for %s.\n",
pdata->sensor_name);

+ if (fn->dev.of_node) {
+ pdata->f11_sensor_data = kzalloc(
+ sizeof(struct rmi_f11_sensor_data),
+ GFP_KERNEL);
+ if (!pdata->f11_sensor_data)
+ return -ENOMEM;
+
+ rc = rmi_f11_of_initialize(&fn->dev, pdata);
+ if (rc)
+ return rc;
+ }
+
mask_size = BITS_TO_LONGS(drvdata->irq_count) * sizeof(unsigned long);

/*
diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c
index cf537c9..ab44e14 100644
--- a/drivers/input/rmi4/rmi_i2c.c
+++ b/drivers/input/rmi4/rmi_i2c.c
@@ -12,6 +12,7 @@
#include <linux/module.h>
#include <linux/rmi.h>
#include <linux/slab.h>
+#include <linux/of.h>
#include "rmi_driver.h"

#define BUFFER_SIZE_INCREMENT 32
@@ -183,17 +184,65 @@ static const struct rmi_transport_ops rmi_i2c_ops = {
.read_block = rmi_i2c_read_block,
};

+#ifdef CONFIG_OF
+static int rmi_i2c_of_probe(struct i2c_client *client,
+ struct rmi_device_platform_data *pdata)
+{
+ struct device *dev = &client->dev;
+ int retval;
+
+ dev_info(&client->dev, "%s: client dev of_node: %s (%p)\n", __func__,
+ dev->of_node->name, dev->of_node);
+
+ retval = of_property_read_string(dev->of_node, "syna,sensor-name",
+ &pdata->sensor_name);
+ if (retval && retval != -EINVAL) {
+ dev_err(&client->dev, "Failed to get sensor name: %d\n",
+ retval);
+ return retval;
+ }
+
+ return 0;
+}
+
+static const struct of_device_id rmi_i2c_of_match[] = {
+ { .compatible = "syna,rmi-i2c" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, rmi_i2c_of_match);
+#else
+static inline int rmi_i2c_of_probe(struct i2c_client *client,
+ struct rmi_device_platform_data *pdata)
+{
+ return -ENODEV;
+}
+#endif
+
static int rmi_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- const struct rmi_device_platform_data *pdata =
+ struct rmi_device_platform_data *pdata =
dev_get_platdata(&client->dev);
struct rmi_i2c_xport *rmi_i2c;
int retval;

if (!pdata) {
- dev_err(&client->dev, "no platform data\n");
- return -EINVAL;
+ if (client->dev.of_node) {
+ pdata = kzalloc(
+ sizeof(struct rmi_device_platform_data),
+ GFP_KERNEL);
+ if (!pdata)
+ return -ENOMEM;
+
+ retval = rmi_i2c_of_probe(client, pdata);
+ if (retval)
+ return retval;
+
+ client->dev.platform_data = pdata;
+ } else {
+ dev_err(&client->dev, "no platform data\n");
+ return -EINVAL;
+ }
}

dev_dbg(&client->dev, "Probing %s at %#02x.\n",
@@ -261,7 +310,8 @@ MODULE_DEVICE_TABLE(i2c, rmi_id);
static struct i2c_driver rmi_i2c_driver = {
.driver = {
.owner = THIS_MODULE,
- .name = "rmi_i2c"
+ .name = "rmi_i2c",
+ .of_match_table = of_match_ptr(rmi_i2c_of_match),
},
.id_table = rmi_id,
.probe = rmi_i2c_probe,
diff --git a/include/linux/rmi.h b/include/linux/rmi.h
index 2f3c79d..1dd0591 100644
--- a/include/linux/rmi.h
+++ b/include/linux/rmi.h
@@ -241,7 +241,7 @@ struct rmi_device_platform_data_spi {
* functions.
*/
struct rmi_device_platform_data {
- char *sensor_name; /* Used for diagnostics. */
+ const char *sensor_name; /* Used for diagnostics. */

int poll_interval_ms;

--
2.1.4

2015-08-13 19:43:34

by Benjamin Tissoires

[permalink] [raw]
Subject: Re: [PATCH v2] Input: synaptics-rmi4: Add device tree support for RMI4 I2C devices

On Aug 13 2015 or thereabouts, Andrew Duggan wrote:
> Add devicetree binding for I2C devices and add bindings for optional
> parameters in the function drivers. Parameters for function drivers are
> defined in child nodes for each of the functions.
>
> Signed-off-by: Andrew Duggan <[email protected]>
> ---
> This version depends on the "Use generic interrupt handling" patch so that
> it can leverage the generic interrupt bindings.
>
> Thanks,
> Andrew
>
> .../devicetree/bindings/input/rmi4/rmi_f01.txt | 37 ++++++
> .../devicetree/bindings/input/rmi4/rmi_f11.txt | 54 +++++++++
> .../devicetree/bindings/input/rmi4/rmi_i2c.txt | 51 ++++++++
> .../devicetree/bindings/vendor-prefixes.txt | 1 +
> drivers/input/rmi4/rmi_bus.c | 70 +++++++++++
> drivers/input/rmi4/rmi_bus.h | 8 +-
> drivers/input/rmi4/rmi_driver.c | 34 +++++-
> drivers/input/rmi4/rmi_f01.c | 50 +++++++-
> drivers/input/rmi4/rmi_f11.c | 133 ++++++++++++++++++++-
> drivers/input/rmi4/rmi_i2c.c | 58 ++++++++-
> include/linux/rmi.h | 2 +-
> 11 files changed, 489 insertions(+), 9 deletions(-)
> create mode 100644 Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt
> create mode 100644 Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt
> create mode 100644 Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt
>
> diff --git a/Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt b/Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt
> new file mode 100644
> index 0000000..63a1793
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/rmi4/rmi_f01.txt
> @@ -0,0 +1,37 @@
> +Synaptics RMI4 F01 Device Binding
> +
> +The Synaptics RMI4 core is able to support RMI4 devices using differnet
> +transports and differnet functions. This file describes the device tree
> +bindings for devices which contain Function 1. Complete documentation
> +for transports and other functions can be found in:
> +Documentation/devicetree/bindings/input/rmi4.
> +
> +Additional documentation for F01 can be found at:
> +http://www.synaptics.com/sites/default/files/511-000136-01-Rev-E-RMI4-Interfacing-Guide.pdf
> +
> +Optional Properties:
> +- syna,nosleep: If set the device will run at full power without sleeping.
> +- syna,wakeup-threshold: Defines the amplitude of the disturbance to the
> + background capacitance that will cause the
> + device to wake from dozing.
> +- syna,doze-holdoff: The delay to wait after the last finger lift and the
> + first doze cycle (in 0.1 second units).
> +- syna,doze-interval: The time period that the device sleeps between finger
> + activity (in 10 ms units).
> +
> +
> +Example of a RMI4 I2C device with F01:
> + Example:
> + &i2c1 {
> + rmi-i2c-dev@2c {
> + compatible = "syna,rmi-i2c";
> +
> + ...
> +
> + rmi-f01@1 {
> + reg = <0x1>;
> + syna,nosleep = <1>;
> + };
> + };
> + };
> +
> diff --git a/Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt b/Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt
> new file mode 100644
> index 0000000..8236a1f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/rmi4/rmi_f11.txt
> @@ -0,0 +1,54 @@
> +Synaptics RMI4 F11 Device Binding
> +
> +The Synaptics RMI4 core is able to support RMI4 devices using differnet
> +transports and differnet functions. This file describes the device tree
> +bindings for devices which contain Function 11. Complete documentation
> +for transports and other functions can be found in:
> +Documentation/devicetree/bindings/input/rmi4.
> +
> +RMI4 Function 11 is for 2D touch position sensing. Additional documentation for
> +F11 can be found at:
> +http://www.synaptics.com/sites/default/files/511-000136-01-Rev-E-RMI4-Interfacing-Guide.pdf
> +
> +Optional Properties:
> +- syna,swap-axes: Swap X and Y positions when reporting.
> +- syna,flip-x: Reverse the direction of X.
> +- syna,flip-y: Reverse the direction of Y.
> +- syna,clip-x-low: Sets a minimum value for X.
> +- syna,clip-y-low: Sets a minimum value for Y.
> +- syna,clip-x-high: Sets a maximum value for X.
> +- syna,clip-y-high: Sets a maximum value for Y.
> +- syna,offset-x: Add an offset to X.
> +- syna,offset_y: Add an offset to Y.
> +- syna,delta-x-threshold: Set the minimum distance on the X axis required
> + to generate an interrupt in reduced reporting
> + mode.
> +- syna,delta-y-threshold: Set the minimum distance on the Y axis required
> + to generate an interrupt in reduced reporting
> + mode.
> +- syna,type-a: Report type A multitouch events.
> +- syna,sensor-type: Set the sensor type. 1 for touchscreen 2 for touchpad.
> +- syna,x-mm: The length in millimeters of the X axis.
> +- syna,y-mm: The length in millimeters of the Y axis.
> +- syna,disable-report-mask: Mask for disabling posiiton reporting. Used to
> + disable reporing absolute position data.
> +- syna,rezero-wait: Time in miliseconds to wait after issuing a rezero
> + command.
> +
> +
> +Example of a RMI4 I2C device with F11:
> +Example:
> + &i2c1 {
> + rmi-i2c-dev@2c {
> + compatible = "syna,rmi-i2c";
> +
> + ...
> +
> + rmi-f11@11 {
> + reg = <0x11>;
> + syna,flip-y = <1>;
> + syna,sensor-type = <2>;
> + };
> + };
> + };
> +
> diff --git a/Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt b/Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt
> new file mode 100644
> index 0000000..e3fcacd
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/input/rmi4/rmi_i2c.txt
> @@ -0,0 +1,51 @@
> +Synaptics RMI4 I2C Device Binding
> +
> +The Synaptics RMI4 core is able to support RMI4 devices using differnet
> +transports and differnet functions. This file describes the device tree
> +bindings for devices using the I2C tranport driver. Complete documentation
> +for other transports and functions cen be found ini
> +Documentation/devicetree/bindings/input/rmi4.
> +
> +Required Properties:
> +- compatible: syna,rmi-i2c
> +- reg: I2C address
> +
> +Optional Properties:
> +- interrupts: interrupt which the rmi device is connected to.
> +- interrupt-parent: The interrupt controller.
> +See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
> +
> +- syna,sensor-name: The string containing the name of the sensor.
> +- syna,poll-interval-ms: The interval in milliseconds to wait between reading
> + interrupts when the driver is polling.
> +- syna,reset-delay-ms: The number of milliseconds to wait after resetting the
> + device.
> +
> +Function Parameters:
> +Parameters specific to RMI functions are contained in child nodes of the rmi device
> + node. Documentation for the parameters of each function can be found in:
> +Documentation/devicetree/bindings/input/rmi4/rmi_f*.txt.
> +
> +
> +
> +Example:
> + &i2c1 {
> + rmi-i2c-dev@2c {
> + compatible = "syna,rmi-i2c";
> + reg = <0x2c>;
> + interrupt-parent = <&gpio>;
> + interrupts = <4 2>;
> + syna,sensor-name="TM1949";
> +
> + rmi-f01@1 {
> + reg = <0x1>;
> + syna,f01-nosleep = <1>;
> + };
> +
> + rmi-f11@11 {
> + reg = <0x11>;
> + syna,f11-flip-y = <1>;
> + syna,f11-sensor-type = <2>;
> + };
> + };
> + };
> diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
> index 40ce2df..3ea0a43 100644
> --- a/Documentation/devicetree/bindings/vendor-prefixes.txt
> +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
> @@ -85,6 +85,7 @@ spansion Spansion Inc.
> st STMicroelectronics
> ste ST-Ericsson
> stericsson ST-Ericsson
> +syna Synaptics Inc.
> ti Texas Instruments
> tlm Trusted Logic Mobility
> toshiba Toshiba Corporation
> diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
> index 6e0454a..26f9f17 100644
> --- a/drivers/input/rmi4/rmi_bus.c
> +++ b/drivers/input/rmi4/rmi_bus.c
> @@ -16,6 +16,7 @@
> #include <linux/slab.h>
> #include <linux/types.h>
> #include <linux/debugfs.h>
> +#include <linux/of.h>
> #include "rmi_bus.h"
> #include "rmi_driver.h"
>
> @@ -203,6 +204,21 @@ static int rmi_function_match(struct device *dev, struct device_driver *drv)
> return fn->fd.function_number == handler->func;
> }
>
> +#ifdef CONFIG_OF
> +static void rmi_function_of_probe(struct rmi_function *fn)
> +{
> + char of_name[8];
> +
> + snprintf(of_name, sizeof(of_name), "rmi-f%02x",
> + fn->fd.function_number);
> + fn->dev.of_node = of_find_node_by_name(
> + fn->rmi_dev->xport->dev->of_node, of_name);
> +}
> +#else
> +static inline void rmi_function_of_probe(struct rmi_function *fn)
> +{}
> +#endif
> +
> static int rmi_function_probe(struct device *dev)
> {
> struct rmi_function *fn = to_rmi_function(dev);
> @@ -210,6 +226,8 @@ static int rmi_function_probe(struct device *dev)
> to_rmi_function_handler(dev->driver);
> int error;
>
> + rmi_function_of_probe(fn);
> +
> if (handler->probe) {
> error = handler->probe(fn);
> return error;
> @@ -267,6 +285,10 @@ void rmi_unregister_function(struct rmi_function *fn)
> {
> device_del(&fn->dev);
> rmi_function_teardown_debugfs(fn);
> +
> + if (fn->dev.of_node)
> + of_node_put(fn->dev.of_node);
> +
> put_device(&fn->dev);
> }
>
> @@ -335,6 +357,54 @@ struct bus_type rmi_bus_type = {
> .name = "rmi",
> };
>
> +int rmi_of_property_read_u32(struct device *dev, u32 *result,
> + const char *prop, bool optional)
> +{
> + int retval;
> + u32 val = 0;
> +
> + retval = of_property_read_u32(dev->of_node, prop, &val);
> + if (retval && (!optional && retval == -EINVAL)) {
> + dev_err(dev, "Failed to get %s value: %d\n",
> + prop, retval);
> + return retval;
> + }
> + *result = val;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(rmi_of_property_read_u32);
> +
> +int rmi_of_property_read_u16(struct device *dev, u16 *result,
> + const char *prop, bool optional)
> +{
> + int retval;
> + u32 val = 0;
> +
> + retval = rmi_of_property_read_u32(dev, &val, prop, optional);
> + if (retval)
> + return retval;
> + *result = val;
> +
> + return retval;
> +}
> +EXPORT_SYMBOL_GPL(rmi_of_property_read_u16);
> +
> +int rmi_of_property_read_u8(struct device *dev, u8 *result,
> + const char *prop, bool optional)
> +{
> + int retval;
> + u32 val = 0;
> +
> + retval = rmi_of_property_read_u32(dev, &val, prop, optional);
> + if (retval)
> + return retval;
> + *result = val;
> +
> + return retval;
> +}
> +EXPORT_SYMBOL_GPL(rmi_of_property_read_u8);

I wonder if we really need those overloading of of_property_read_u32.

> +
> #ifdef CONFIG_RMI4_DEBUG
>
> static void rmi_bus_setup_debugfs(void)
> diff --git a/drivers/input/rmi4/rmi_bus.h b/drivers/input/rmi4/rmi_bus.h
> index 4e3bca3..2241bd8 100644
> --- a/drivers/input/rmi4/rmi_bus.h
> +++ b/drivers/input/rmi4/rmi_bus.h
> @@ -226,7 +226,7 @@ struct rmi_device {
>
> #define to_rmi_device(d) container_of(d, struct rmi_device, dev)
>
> -static inline const struct rmi_device_platform_data *
> +static inline struct rmi_device_platform_data *
> rmi_get_platform_data(struct rmi_device *d)
> {
> return dev_get_platdata(d->xport->dev);
> @@ -317,4 +317,10 @@ int rmi_for_each_dev(void *data, int (*func)(struct device *dev, void *data));
>
> extern struct bus_type rmi_bus_type;
>
> +int rmi_of_property_read_u32(struct device *dev, u32 *result,
> + const char *prop, bool optional);
> +int rmi_of_property_read_u16(struct device *dev, u16 *result,
> + const char *prop, bool optional);
> +int rmi_of_property_read_u8(struct device *dev, u8 *result,
> + const char *prop, bool optional);
> #endif
> diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c
> index 585bd7b..67cd7fa 100644
> --- a/drivers/input/rmi4/rmi_driver.c
> +++ b/drivers/input/rmi4/rmi_driver.c
> @@ -717,11 +717,37 @@ static int rmi_driver_remove(struct device *dev)
> return 0;
> }
>
> +#ifdef CONFIG_OF
> +static int rmi_driver_of_probe(struct device *dev,
> + struct rmi_device_platform_data *pdata)
> +{
> + int retval;
> +
> + retval = rmi_of_property_read_u32(dev, &pdata->poll_interval_ms,
> + "syna,poll-interval-ms", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u32(dev, &pdata->reset_delay_ms,
> + "syna,reset-delay-ms", 1);
> + if (retval)
> + return retval;
> +
> + return 0;
> +}
> +#else
> +static inline int rmi_driver_of_probe(struct device *dev,
> + struct rmi_device_platform_data *pdata)
> +{
> + return -ENODEV;
> +}
> +#endif
> +
> static int rmi_driver_probe(struct device *dev)
> {
> struct rmi_driver *rmi_driver;
> struct rmi_driver_data *data;
> - const struct rmi_device_platform_data *pdata;
> + struct rmi_device_platform_data *pdata;
> struct rmi_device *rmi_dev;
> size_t size;
> void *irq_memory;
> @@ -741,6 +767,12 @@ static int rmi_driver_probe(struct device *dev)
>
> pdata = rmi_get_platform_data(rmi_dev);
>
> + if (rmi_dev->xport->dev->of_node) {
> + retval = rmi_driver_of_probe(rmi_dev->xport->dev, pdata);
> + if (retval)
> + return retval;
> + }
> +
> data = kzalloc(sizeof(struct rmi_driver_data), GFP_KERNEL);
> if (!data) {
> dev_err(dev, "%s: Failed to allocate driver data.\n", __func__);
> diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c
> index ee5f4a1..9882593 100644
> --- a/drivers/input/rmi4/rmi_f01.c
> +++ b/drivers/input/rmi4/rmi_f01.c
> @@ -12,6 +12,7 @@
> #include <linux/rmi.h>
> #include <linux/slab.h>
> #include <linux/uaccess.h>
> +#include <linux/of.h>
> #include "rmi_driver.h"
>
> #define RMI_PRODUCT_ID_LENGTH 10
> @@ -176,16 +177,63 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev,
> return 0;
> }
>
> +#ifdef CONFIG_OF
> +static int rmi_f01_of_probe(struct device *dev,
> + struct rmi_device_platform_data *pdata)
> +{
> + int retval;
> +
> + retval = rmi_of_property_read_u32(dev,
> + (u32 *)&pdata->power_management.nosleep,
> + "syna,nosleep", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u8(dev,
> + &pdata->power_management.wakeup_threshold,
> + "syna,wakeup-threshold", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u8(dev,
> + &pdata->power_management.doze_holdoff,
> + "syna,doze-holdoff", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u8(dev,
> + &pdata->power_management.doze_interval,
> + "syna,doze-interval", 1);
> + if (retval)
> + return retval;
> +
> + return 0;
> +}
> +#else
> +static inline int rmi_f01_of_probe(struct device *dev,
> + struct rmi_device_platform_data *pdata)
> +{
> + return -ENODEV;
> +}
> +#endif
> +
> static int rmi_f01_probe(struct rmi_function *fn)
> {
> struct rmi_device *rmi_dev = fn->rmi_dev;
> struct rmi_driver_data *driver_data = dev_get_drvdata(&rmi_dev->dev);
> - const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
> + struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
> struct f01_data *f01;
> int error;
> u16 ctrl_base_addr = fn->fd.control_base_addr;
> u8 device_status;
> u8 temp;
> + int retval;
> +
> + if (fn->dev.of_node) {
> + retval = rmi_f01_of_probe(&fn->dev, pdata);
> + if (retval)
> + return retval;
> + }
>
> f01 = devm_kzalloc(&fn->dev, sizeof(struct f01_data), GFP_KERNEL);
> if (!f01) {
> diff --git a/drivers/input/rmi4/rmi_f11.c b/drivers/input/rmi4/rmi_f11.c
> index 7af4f68..56add28 100644
> --- a/drivers/input/rmi4/rmi_f11.c
> +++ b/drivers/input/rmi4/rmi_f11.c
> @@ -15,6 +15,7 @@
> #include <linux/kconfig.h>
> #include <linux/rmi.h>
> #include <linux/slab.h>
> +#include <linux/of.h>
> #include "rmi_driver.h"
>
> #define F11_MAX_NUM_OF_FINGERS 10
> @@ -1206,6 +1207,124 @@ static void f11_set_abs_params(struct rmi_function *fn, struct f11_data *f11)
> 0, MT_TOOL_FINGER, 0, 0);
> }
>
> +#ifdef CONFIG_OF
> +static int rmi_f11_of_initialize(struct device *dev,
> + struct rmi_device_platform_data *pdata)
> +{
> + u32 val;
> + int retval;
> +
> + retval = rmi_of_property_read_u32(dev,
> + &pdata->f11_sensor_data->axis_align.swap_axes,
> + "syna,swap-axes", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u32(dev,
> + &pdata->f11_sensor_data->axis_align.flip_x,
> + "syna,flip-x", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u32(dev,
> + &pdata->f11_sensor_data->axis_align.flip_y,
> + "syna,flip-y", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u16(dev,
> + &pdata->f11_sensor_data->axis_align.clip_x_low,
> + "syna,clip-x-low", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u16(dev,
> + &pdata->f11_sensor_data->axis_align.clip_y_low,
> + "syna,clip-y-low", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u16(dev,
> + &pdata->f11_sensor_data->axis_align.clip_x_high,
> + "syna,clip-x-high", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u16(dev,
> + &pdata->f11_sensor_data->axis_align.clip_y_high,
> + "syna,clip-y-high", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u16(dev,
> + &pdata->f11_sensor_data->axis_align.offset_x,
> + "syna,offset-x", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u16(dev,
> + &pdata->f11_sensor_data->axis_align.offset_y,
> + "syna,offset_y", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u8(dev,
> + &pdata->f11_sensor_data->axis_align.delta_x_threshold,
> + "syna,delta-x-threshold", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u8(dev,
> + &pdata->f11_sensor_data->axis_align.delta_y_threshold,
> + "syna,delta-y-threshold", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u32(dev, &val,
> + "syna,type-a", 1);
> + if (retval)
> + return retval;
> + pdata->f11_sensor_data->type_a = !!val;
> +
> + retval = rmi_of_property_read_u32(dev,
> + (u32 *)&pdata->f11_sensor_data->sensor_type,
> + "syna,sensor-type", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u32(dev,
> + (u32 *)&pdata->f11_sensor_data->x_mm,
> + "syna,x-mm", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u32(dev,
> + (u32 *)&pdata->f11_sensor_data->y_mm,
> + "syna,y-mm", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u32(dev,
> + (u32 *)&pdata->f11_sensor_data->disable_report_mask,
> + "syna,disable-report-mask", 1);
> + if (retval)
> + return retval;
> +
> + retval = rmi_of_property_read_u16(dev, &pdata->f11_rezero_wait,
> + "syna,rezero-wait", 1);
> + if (retval)
> + return retval;
> +
> + return 0;
> +}
> +#else
> +static inline int rmi_f11_of_initialize(struct device *dev,
> + struct rmi_device_platform_data *pdata)
> +{
> + return -ENODEV;
> +}
> +#endif
> +
> static int rmi_f11_initialize(struct rmi_function *fn)
> {
> struct rmi_device *rmi_dev = fn->rmi_dev;
> @@ -1216,7 +1335,7 @@ static int rmi_f11_initialize(struct rmi_function *fn)
> u16 control_base_addr;
> u16 max_x_pos, max_y_pos, temp;
> int rc;
> - const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
> + struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev);
> struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
> struct f11_2d_sensor *sensor;
> u8 buf;
> @@ -1225,6 +1344,18 @@ static int rmi_f11_initialize(struct rmi_function *fn)
> dev_dbg(&fn->dev, "Initializing F11 values for %s.\n",
> pdata->sensor_name);
>
> + if (fn->dev.of_node) {
> + pdata->f11_sensor_data = kzalloc(
> + sizeof(struct rmi_f11_sensor_data),
> + GFP_KERNEL);
> + if (!pdata->f11_sensor_data)
> + return -ENOMEM;
> +
> + rc = rmi_f11_of_initialize(&fn->dev, pdata);
> + if (rc)
> + return rc;
> + }
> +
> mask_size = BITS_TO_LONGS(drvdata->irq_count) * sizeof(unsigned long);
>
> /*
> diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c
> index cf537c9..ab44e14 100644
> --- a/drivers/input/rmi4/rmi_i2c.c
> +++ b/drivers/input/rmi4/rmi_i2c.c
> @@ -12,6 +12,7 @@
> #include <linux/module.h>
> #include <linux/rmi.h>
> #include <linux/slab.h>
> +#include <linux/of.h>
> #include "rmi_driver.h"
>
> #define BUFFER_SIZE_INCREMENT 32
> @@ -183,17 +184,65 @@ static const struct rmi_transport_ops rmi_i2c_ops = {
> .read_block = rmi_i2c_read_block,
> };
>
> +#ifdef CONFIG_OF
> +static int rmi_i2c_of_probe(struct i2c_client *client,
> + struct rmi_device_platform_data *pdata)
> +{
> + struct device *dev = &client->dev;
> + int retval;
> +
> + dev_info(&client->dev, "%s: client dev of_node: %s (%p)\n", __func__,
> + dev->of_node->name, dev->of_node);
> +
> + retval = of_property_read_string(dev->of_node, "syna,sensor-name",
> + &pdata->sensor_name);
> + if (retval && retval != -EINVAL) {
> + dev_err(&client->dev, "Failed to get sensor name: %d\n",
> + retval);
> + return retval;
> + }
> +
> + return 0;
> +}
> +
> +static const struct of_device_id rmi_i2c_of_match[] = {
> + { .compatible = "syna,rmi-i2c" },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, rmi_i2c_of_match);
> +#else
> +static inline int rmi_i2c_of_probe(struct i2c_client *client,
> + struct rmi_device_platform_data *pdata)
> +{
> + return -ENODEV;
> +}
> +#endif
> +
> static int rmi_i2c_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> - const struct rmi_device_platform_data *pdata =
> + struct rmi_device_platform_data *pdata =
> dev_get_platdata(&client->dev);
> struct rmi_i2c_xport *rmi_i2c;
> int retval;
>
> if (!pdata) {
> - dev_err(&client->dev, "no platform data\n");
> - return -EINVAL;
> + if (client->dev.of_node) {
> + pdata = kzalloc(
> + sizeof(struct rmi_device_platform_data),
> + GFP_KERNEL);

I just gave a quick look at the patch, and I think you might be leaking
memory here.

I think the best approach is to do the same we did in i2c-hid: store the
platform data in rmi_i2c directly, and if there is a pdata, copy it to
rmi_i2c, if not, then fill up the data from OF.

Cheers,
Benjamin

> + if (!pdata)
> + return -ENOMEM;
> +
> + retval = rmi_i2c_of_probe(client, pdata);
> + if (retval)
> + return retval;
> +
> + client->dev.platform_data = pdata;
> + } else {
> + dev_err(&client->dev, "no platform data\n");
> + return -EINVAL;
> + }
> }
>
> dev_dbg(&client->dev, "Probing %s at %#02x.\n",
> @@ -261,7 +310,8 @@ MODULE_DEVICE_TABLE(i2c, rmi_id);
> static struct i2c_driver rmi_i2c_driver = {
> .driver = {
> .owner = THIS_MODULE,
> - .name = "rmi_i2c"
> + .name = "rmi_i2c",
> + .of_match_table = of_match_ptr(rmi_i2c_of_match),
> },
> .id_table = rmi_id,
> .probe = rmi_i2c_probe,
> diff --git a/include/linux/rmi.h b/include/linux/rmi.h
> index 2f3c79d..1dd0591 100644
> --- a/include/linux/rmi.h
> +++ b/include/linux/rmi.h
> @@ -241,7 +241,7 @@ struct rmi_device_platform_data_spi {
> * functions.
> */
> struct rmi_device_platform_data {
> - char *sensor_name; /* Used for diagnostics. */
> + const char *sensor_name; /* Used for diagnostics. */
>
> int poll_interval_ms;
>
> --
> 2.1.4
>