Skip to content

Commit

Permalink
Input: rmi_i2c: introduce reset GPIO handling
Browse files Browse the repository at this point in the history
Implement reset GPIO handling logic for the rmi_i2c driver. This logic
is required for some mobile devices to successfully initialize the touch
controller.

As there are no datasheets available, the timings were taken from the
GPLv2+ licensed synaptics-dsx-v2.1 vendor driver release.

Tested-On: Motorola G5 Plus (Potter / XT1685)

Signed-off-by: Felix Kaechele <[email protected]>
  • Loading branch information
kaechele authored and barni2000 committed Jan 30, 2025
1 parent 39aa0e7 commit dd26b8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion drivers/input/rmi4/rmi_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#define RMI4_PAGE_MASK 0xFF00

#define RMI_DEVICE_RESET_CMD 0x01
#define DEFAULT_RESET_DELAY_MS 100

void rmi_free_function_list(struct rmi_device *rmi_dev)
{
Expand Down
2 changes: 2 additions & 0 deletions drivers/input/rmi4/rmi_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define SYNAPTICS_INPUT_DEVICE_NAME "Synaptics RMI4 Touch Sensor"
#define SYNAPTICS_VENDOR_ID 0x06cb

#define DEFAULT_RESET_DELAY_MS 100

#define GROUP(_attrs) { \
.attrs = _attrs, \
}
Expand Down
23 changes: 23 additions & 0 deletions drivers/input/rmi4/rmi_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2011 Unixphere
*/

#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/rmi.h>
#include <linux/of.h>
Expand All @@ -26,7 +27,9 @@
* @tx_buf_size: Size of the buffer
*
* @supplies: Array of voltage regulators
* @reset_gpio: Reference to the reset GPIO
* @startup_delay: Milliseconds to pause after powering up the regulators
* @reset_delay: Milliseconds to pause after resetting the device
*/
struct rmi_i2c_xport {
struct rmi_transport_dev xport;
Expand All @@ -39,7 +42,9 @@ struct rmi_i2c_xport {
size_t tx_buf_size;

struct regulator_bulk_data supplies[2];
struct gpio_desc *reset_gpio;
u32 startup_delay;
u32 reset_delay;
};

#define RMI_PAGE_SELECT_REGISTER 0xff
Expand Down Expand Up @@ -227,6 +232,15 @@ static int rmi_i2c_probe(struct i2c_client *client)
return -ENODEV;
}

rmi_i2c->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
GPIOD_OUT_HIGH);
if (IS_ERR(rmi_i2c->reset_gpio)) {
error = PTR_ERR(rmi_i2c->reset_gpio);
dev_err(&client->dev, "failed to get reset GPIO: %d\n", error);
return error;
}
gpiod_set_consumer_name(rmi_i2c->reset_gpio, "rmi4 reset");

rmi_i2c->supplies[0].supply = "vdd";
rmi_i2c->supplies[1].supply = "vio";
error = devm_regulator_bulk_get(&client->dev,
Expand All @@ -251,6 +265,15 @@ static int rmi_i2c_probe(struct i2c_client *client)

msleep(rmi_i2c->startup_delay);

if (rmi_i2c->reset_gpio) {
of_property_read_u32(client->dev.of_node, "syna,reset-delay-ms",
&rmi_i2c->reset_delay);
gpiod_set_value_cansleep(rmi_i2c->reset_gpio, 1);
usleep_range(10000, 20000);
gpiod_set_value_cansleep(rmi_i2c->reset_gpio, 0);
msleep(rmi_i2c->reset_delay ?: DEFAULT_RESET_DELAY_MS);
}

rmi_i2c->client = client;
mutex_init(&rmi_i2c->page_mutex);

Expand Down

0 comments on commit dd26b8f

Please sign in to comment.