DRV260x: Support ACPI-enumerated devices
Subsystems (2)
v2 cover DRV260x: Support ACPI-enumerated devices
Lenovo Yoga Book YB1-X90 and YB1-X91 tablets use haptics controllers DRV2604L. The X91 (Windows tablet) uses ACPI to define its configuration, such as I2C address and GPIO connections. The X90 (Android tablet) doesn't have it in the ACPI, but the device may be defined as an i2c_board in the x86-android-tablets driver.
To support these variants, add an ACPI matching table and add additional I2C IDs to the I2C matching table (the driver supports DRV2604(L), DRV2605(L) devices).
Also, implement a timeout for waiting for calibration,
and fix the non-working suspend due to unbalanced regulator_disable() call.
Changes in v2:
- Header includes have been sorted alphabetically;
- ACPI GPIO mapping has been removed (supposed to be in the device-specific driver like x86-android-tablets);
- Old debug session artifacts removed;
- Checking of device ID has been removed; the driver uses the same logic for all drv260x(L) variants;
- Timeout during calibration reports an error; we don't expect that the chip will work properly in such a case;
- Patch regarding the regulator has been reworked; now it just adds regulator_enable()/regulator_disable() during device probing and removal.
Discussion of v1 is here:
Yauhen Kharuzhy (5):
input: drv260x: Add I2C IDs for all device variants
input: drv260x: Sort all #include alphabetically
input: drv260x: Add support for ACPI-enumerated devices
input: drv260x: Fix unbalanced regulator_disable() call
input: drv260x: Handle calibration timeout
drivers/input/misc/drv260x.c | 55 ++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-)
base-commit: 9845cf73f7db6094c0d8419d6adb848028f4a921
Signature · 1 line
2.51.0
PATCH v2 1/5 input: drv260x: Add I2C IDs for all device variants
Add drv2604(L) and drv2605 to the list of supported I2C device IDs for clarity.
--- drivers/input/misc/drv260x.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/input/misc/drv260x.c +3 -0
@@ -598,6 +598,9 @@ static int drv260x_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(drv260x_pm_ops, drv260x_suspend, drv260x_resume);static const struct i2c_device_id drv260x_id[] = { + {"drv2604" }, + {"drv2604l" }, + {"drv2605" }, {"drv2605l" }, { } };
Signature · 1 line
2.51.0
PATCH v2 2/5 input: drv260x: Sort all #include alphabetically
In reply to Yauhen KharuzhySort all #include directives alphabetically before adding new entries.
--- drivers/input/misc/drv260x.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/input/misc/drv260x.c +3 -3
@@ -7,14 +7,14 @@* Copyright: (C) 2014 Texas Instruments, Inc. */ +#include <linux/delay.h> +#include <linux/gpio/consumer.h> #include <linux/i2c.h> #include <linux/input.h> #include <linux/module.h> #include <linux/regmap.h> -#include <linux/slab.h> -#include <linux/delay.h> -#include <linux/gpio/consumer.h> #include <linux/regulator/consumer.h> +#include <linux/slab.h> #include <dt-bindings/input/ti-drv260x.h>
Signature · 1 line
2.51.0
PATCH v2 3/5 input: drv260x: Add support for ACPI-enumerated devices
In reply to Yauhen KharuzhyAdd ACPI ids and GPIO lookup mapping for drv2604 haptics device. Found in Lenovo Yoga Book YB1-X91L tablet.
--- drivers/input/misc/drv260x.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/input/misc/drv260x.c +10 -0
@@ -7,6 +7,7 @@* Copyright: (C) 2014 Texas Instruments, Inc. */ +#include <linux/acpi.h> #include <linux/delay.h> #include <linux/gpio/consumer.h> #include <linux/i2c.h>
@@ -606,6 +607,14 @@ static const struct i2c_device_id drv260x_id[] = { };MODULE_DEVICE_TABLE (i2c, drv260x_id); +#ifdef CONFIG_ACPI +static const struct acpi_device_id drv260x_acpi_match[] = { + {"DRV2604" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, drv260x_acpi_match); +#endif +static const struct of_device_id drv260x_of_match[] = { { .compatible ="ti,drv2604" , }, { .compatible ="ti,drv2604l" , },
@@ -621,6 +630,7 @@ static struct i2c_driver drv260x_driver = { .name = "drv260x-haptics", .of_match_table = drv260x_of_match, .pm = pm_sleep_ptr(&drv260x_pm_ops), + .acpi_match_table = ACPI_PTR(drv260x_acpi_match), }, .id_table = drv260x_id, };
Signature · 1 line
2.51.0
PATCH v2 4/5 input: drv260x: Fix unbalanced regulator_disable() call
In reply to Yauhen KharuzhyThe driver acquires the 'vbat' regulator during probing but never enables it. Consequently, in the suspend method, the driver disables the regulator without enabling it first, causing an 'Unbalanced regulator_disable()' error.
Enable the regulator in the probe() method and add the remove() method with regulator disabling to fix this.
--- drivers/input/misc/drv260x.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/input/misc/drv260x.c +21 -2
@@ -520,19 +520,37 @@ static int drv260x_probe(struct i2c_client *client)return error; } + error =regulator_enable (haptics->regulator); +if (error) { +dev_err (dev,"Failed to enable regulator\n" ); +return error; + } + error =drv260x_init (haptics);if (error) {dev_err (dev,"Device init failed: %d\n" , error); -return error; + goto err_regulator_disable; } error =input_register_device (haptics->input_dev);if (error) {dev_err (dev,"couldn't register input device: %d\n" , error); -return error; + goto err_regulator_disable; }return 0 ; + +err_regulator_disable: +regulator_disable (haptics->regulator); + +return error; +} + +static void drv260x_remove (struct i2c_client *client) +{ +struct drv260x_data *haptics =i2c_get_clientdata (client); + +regulator_disable (haptics->regulator); }static int drv260x_suspend (struct device *dev)
@@ -626,6 +644,7 @@ MODULE_DEVICE_TABLE(of, drv260x_of_match);static struct i2c_driver drv260x_driver = { .probe = drv260x_probe, + .remove = drv260x_remove, .driver = { .name ="drv260x-haptics" , .of_match_table = drv260x_of_match,
Signature · 1 line
2.51.0
PATCH v2 5/5 input: drv260x: Handle calibration timeout
In reply to Yauhen KharuzhyIf something goes wrong during calibration (for instance, if the 'enable' GPIO was not properly defined), the GO bit may not be cleared after some time, causing the driver to get stuck.
To prevent this, add a timeout check to the waiting loop and return an error if it times out.
--- drivers/input/misc/drv260x.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/input/misc/drv260x.c +13 -0
@@ -166,6 +166,12 @@#define DRV260X_AUTOCAL_TIME_500MS (2 << 4)#define DRV260X_AUTOCAL_TIME_1000MS (3 << 4) +/* +* Timeout for waiting for the GO status bit, in seconds. Should be reasonably +* large to wait for a auto-calibration cycle completion. +*/ +#define DRV260X_GO_TIMEOUT_S 5 +/** * struct drv260x_data - * @input_dev: Pointer to the input device
@@ -309,6 +315,7 @@ static int drv260x_init(struct drv260x_data *haptics) {int error;unsigned int cal_buf; +unsigned long timeout; error =regmap_write (haptics->regmap,DRV260X_RATED_VOLT , haptics->rated_voltage);
@@ -398,6 +405,7 @@ static int drv260x_init(struct drv260x_data *haptics)return error; } + timeout = jiffies +DRV260X_GO_TIMEOUT_S *HZ ; do { usleep_range(15000, 15500); error = regmap_read(haptics->regmap, DRV260X_GO, &cal_buf);
@@ -407,6 +415,11 @@ static int drv260x_init(struct drv260x_data *haptics) error);return error; } +if (time_after (jiffies, timeout)) { +dev_err (&haptics->client->dev, +"Calibration timeout. The device cannot be used.\n" ); +return -ETIMEDOUT ; + } }while (cal_buf ==DRV260X_GO_BIT );return 0 ;
Signature · 1 line
2.51.0
Dmitry Torokhov
maintainerRe: [PATCH v2 4/5] input: drv260x: Fix unbalanced regulator_disable() call
In reply to Yauhen KharuzhyHi Yauhen,
drivers/input/misc/drv260x.c static int drv260x_probe(struct i2c_client *client) · line 554
Quoted 6 lines · Yauhen Kharuzhy
drivers/input/misc/drv260x.c +5
-0+static void drv260x_remove (struct i2c_client *client) +{ +struct drv260x_data *haptics =i2c_get_clientdata (client); + +regulator_disable (haptics->regulator); }
This will result in power being shut off the first thing during unbinding, which is too early.
I switched this to devm_add_action_or_reset() and applied.
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerQuoted 6 lines · Yauhen Kharuzhy
Lenovo Yoga Book YB1-X90 and YB1-X91 tablets use haptics controllers DRV2604L. The X91 (Windows tablet) uses ACPI to define its configuration, such as I2C address and GPIO connections. The X90 (Android tablet) doesn't have it in the ACPI, but the device may be defined as an
i2c_boardin the x86-android-tablets driver.
Quoted 6 lines
To support these variants, add an ACPI matching table and add additional I2C IDs to the I2C matching table (the driver supports DRV2604(L), DRV2605(L) devices).
Also, implement a timeout for waiting for calibration,
and fix the non-working suspend due to unbalancedregulator_disable()call.
Applied the series with a small modification in #4.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v2 4/5] input: drv260x: Fix unbalanced regulator_disable() call
In reply to Dmitry TorokhovQuoted 13 lines · Dmitry Torokhov
Hi Yauhen,
drivers/input/misc/drv260x.c static int drv260x_probe(struct i2c_client *client) · line 554
Quoted 6 lines · Yauhen Kharuzhy
drivers/input/misc/drv260x.c +5
-0+static void drv260x_remove (struct i2c_client *client) +{ +struct drv260x_data *haptics =i2c_get_clientdata (client); + +regulator_disable (haptics->regulator); }This will result in power being shut off the first thing during unbinding, which is too early.
Quoted 1 line
I switched this to
devm_add_action_or_reset()and applied.
Do you mean that, in this case, regulator_disable() may be called before any devm_* registered actions? Good point, thanks.
Signature · 1 line
Yauhen Kharuzhy
Dmitry Torokhov
maintainerRe: [PATCH v2 4/5] input: drv260x: Fix unbalanced regulator_disable() call
Quoted 14 lines · Yauhen Kharuzhy
Quoted 13 lines · Dmitry Torokhov
Hi Yauhen,
drivers/input/misc/drv260x.c static int drv260x_probe(struct i2c_client *client) · line 554
Quoted 6 lines · Yauhen Kharuzhy
drivers/input/misc/drv260x.c +5
-0+static void drv260x_remove (struct i2c_client *client) +{ +struct drv260x_data *haptics =i2c_get_clientdata (client); + +regulator_disable (haptics->regulator); }This will result in power being shut off the first thing during unbinding, which is too early.
Quoted 5 lines
Quoted 1 line
I switched this to
devm_add_action_or_reset()and applied.Do you mean that, in this case,
regulator_disable()may be called before any devm_* registered actions? Good point, thanks.
Yes, all devm* actions are run after remove() completes.
Thanks.
Signature · 1 line
Dmitry