From: Irina Tirdea <irina.tirdea@intel.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Bastien Nocera <hadess@hadess.net>,
Mark Rutland <mark.rutland@arm.com>,
linux-input@vger.kernel.org, devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
Pawel Moll <pawel.moll@arm.com>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Kumar Gala <galak@codeaurora.org>,
Irina Tirdea <irina.tirdea@intel.com>
Subject: [PATCH v3 5/5] Input: goodix - add support for ESD
Date: Mon, 29 Jun 2015 19:28:24 +0300 [thread overview]
Message-ID: <1435595304-4840-6-git-send-email-irina.tirdea@intel.com> (raw)
In-Reply-To: <1435595304-4840-1-git-send-email-irina.tirdea@intel.com>
Add ESD (Electrostatic Discharge) protection mechanism.
The driver enables ESD protection in HW and checks a register
to determine if ESD occurred. If ESD is signalled by the HW,
the driver will reset the device.
The ESD poll time (in ms) can be set through the sysfs property
esd_timeout. If it is set to 0, ESD protection is disabled.
Recommended value is 2000 ms. By default, at init ESD protection
is disabled.
The ESD protection mechanism is only available if the gpio pins
are properly initialized from ACPI/DT.
This is based on Goodix datasheets for GT911 and GT9271 and on Goodix
driver gt9xx.c for Android (publicly available in Android kernel
trees for various devices).
Signed-off-by: Irina Tirdea <irina.tirdea@intel.com>
---
drivers/input/touchscreen/goodix.c | 162 +++++++++++++++++++++++++++++++++++--
1 file changed, 156 insertions(+), 6 deletions(-)
diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index 7958d50..91a3454 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -42,6 +42,8 @@ struct goodix_ts_data {
u16 version;
char *cfg_name;
unsigned long irq_flags;
+ atomic_t esd_timeout;
+ struct delayed_work esd_work;
};
struct goodix_gpio_data {
@@ -60,6 +62,8 @@ struct goodix_gpio_data {
/* Register defines */
#define GOODIX_REG_COMMAND 0x8040
#define GOODIX_CMD_SCREEN_OFF 0x05
+#define GOODIX_CMD_ESD_ENABLED 0xAA
+#define GOODIX_REG_ESD_CHECK 0x8041
#define GOODIX_READ_COOR_ADDR 0x814E
#define GOODIX_REG_CONFIG_DATA 0x8047
@@ -366,6 +370,117 @@ static int goodix_reset(struct goodix_ts_data *ts)
return goodix_int_sync(ts);
}
+static void goodix_disable_esd(struct goodix_ts_data *ts)
+{
+ if (!atomic_read(&ts->esd_timeout))
+ return;
+ cancel_delayed_work_sync(&ts->esd_work);
+}
+
+static int goodix_enable_esd(struct goodix_ts_data *ts)
+{
+ int ret, esd_timeout;
+
+ esd_timeout = atomic_read(&ts->esd_timeout);
+ if (!esd_timeout)
+ return 0;
+
+ ret = goodix_i2c_write_u8(ts->client, GOODIX_REG_ESD_CHECK,
+ GOODIX_CMD_ESD_ENABLED);
+ if (ret) {
+ dev_err(&ts->client->dev, "Failed to enable ESD: %d\n", ret);
+ return ret;
+ }
+
+ schedule_delayed_work(&ts->esd_work, round_jiffies_relative(
+ msecs_to_jiffies(esd_timeout)));
+ return 0;
+}
+
+static void goodix_esd_work(struct work_struct *work)
+{
+ struct goodix_ts_data *ts = container_of(work, struct goodix_ts_data,
+ esd_work.work);
+ int retries = 3, ret;
+ u8 esd_data[2];
+ const struct firmware *cfg = NULL;
+
+ while (--retries) {
+ ret = goodix_i2c_read(ts->client, GOODIX_REG_COMMAND, esd_data,
+ sizeof(esd_data));
+ if (ret)
+ continue;
+ if (esd_data[0] != GOODIX_CMD_ESD_ENABLED &&
+ esd_data[1] == GOODIX_CMD_ESD_ENABLED) {
+ /* feed the watchdog */
+ goodix_i2c_write_u8(ts->client,
+ GOODIX_REG_COMMAND,
+ GOODIX_CMD_ESD_ENABLED);
+ break;
+ }
+ }
+
+ if (!retries) {
+ dev_dbg(&ts->client->dev, "Performing ESD recovery.\n");
+ goodix_free_irq(ts);
+ goodix_reset(ts);
+ ret = request_firmware(&cfg, ts->cfg_name, &ts->client->dev);
+ if (!ret) {
+ goodix_send_cfg(ts, cfg);
+ release_firmware(cfg);
+ }
+ goodix_request_irq(ts);
+ goodix_enable_esd(ts);
+ return;
+ }
+
+ schedule_delayed_work(&ts->esd_work, round_jiffies_relative(
+ msecs_to_jiffies(atomic_read(&ts->esd_timeout))));
+}
+
+static ssize_t goodix_esd_timeout_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct goodix_ts_data *ts = dev_get_drvdata(dev);
+
+ return scnprintf(buf, PAGE_SIZE, "%d\n", atomic_read(&ts->esd_timeout));
+}
+
+static ssize_t goodix_esd_timeout_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct goodix_ts_data *ts = dev_get_drvdata(dev);
+ int ret, esd_timeout, new_esd_timeout;
+
+ ret = kstrtouint(buf, 10, &new_esd_timeout);
+ if (ret)
+ return ret;
+
+ esd_timeout = atomic_read(&ts->esd_timeout);
+ if (esd_timeout && !new_esd_timeout)
+ goodix_disable_esd(ts);
+
+ atomic_set(&ts->esd_timeout, new_esd_timeout);
+ if (!esd_timeout && new_esd_timeout)
+ goodix_enable_esd(ts);
+
+ return count;
+}
+
+/* ESD timeout in ms. Default disabled (0). Recommended 2000 ms. */
+static DEVICE_ATTR(esd_timeout, S_IRUGO | S_IWUSR, goodix_esd_timeout_show,
+ goodix_esd_timeout_store);
+
+static struct attribute *goodix_attrs[] = {
+ &dev_attr_esd_timeout.attr,
+ NULL
+};
+
+static const struct attribute_group goodix_attr_group = {
+ .attrs = goodix_attrs,
+};
+
/**
* goodix_get_gpio_config - Get GPIO config from ACPI/DT
*
@@ -608,7 +723,6 @@ static void goodix_config_cb(const struct firmware *cfg, void *ctx)
goodix_configure_dev(ts);
err_release_cfg:
- kfree(ts->cfg_name);
release_firmware(cfg);
}
@@ -631,6 +745,7 @@ static int goodix_ts_probe(struct i2c_client *client,
ts->client = client;
i2c_set_clientdata(client, ts);
+ INIT_DELAYED_WORK(&ts->esd_work, goodix_esd_work);
error = goodix_i2c_test(client);
if (error) {
@@ -656,11 +771,22 @@ static int goodix_ts_probe(struct i2c_client *client,
return error;
}
+ error = sysfs_create_group(&client->dev.kobj,
+ &goodix_attr_group);
+ if (error) {
+ dev_err(&client->dev,
+ "Failed to create sysfs group: %d\n",
+ error);
+ return error;
+ }
+
/* update device config */
ts->cfg_name = kasprintf(GFP_KERNEL, "goodix_%d_cfg.bin",
ts->id);
- if (!ts->cfg_name)
- return -ENOMEM;
+ if (!ts->cfg_name) {
+ error = -ENOMEM;
+ goto err_sysfs_remove_group;
+ }
error = request_firmware_nowait(THIS_MODULE, true, ts->cfg_name,
&client->dev, GFP_KERNEL, ts,
@@ -669,14 +795,32 @@ static int goodix_ts_probe(struct i2c_client *client,
dev_err(&client->dev,
"Failed to invoke firmware loader: %d\n",
error);
- kfree(ts->cfg_name);
- return error;
+ goto err_free_cfg_name;
}
return 0;
}
return goodix_configure_dev(ts);
+
+err_free_cfg_name:
+ if (ts->gpiod_int && ts->gpiod_rst)
+ kfree(ts->cfg_name);
+err_sysfs_remove_group:
+ if (ts->gpiod_int && ts->gpiod_rst)
+ sysfs_remove_group(&client->dev.kobj, &goodix_attr_group);
+ return error;
+}
+
+static int goodix_ts_remove(struct i2c_client *client)
+{
+ struct goodix_ts_data *ts = i2c_get_clientdata(client);
+
+ if (ts->gpiod_int && ts->gpiod_rst)
+ sysfs_remove_group(&client->dev.kobj, &goodix_attr_group);
+ goodix_disable_esd(ts);
+ kfree(ts->cfg_name);
+ return 0;
}
static int __maybe_unused goodix_suspend(struct device *dev)
@@ -689,6 +833,7 @@ static int __maybe_unused goodix_suspend(struct device *dev)
if (!ts->gpiod_int || !ts->gpiod_rst)
return 0;
+ goodix_disable_esd(ts);
/* Free IRQ as IRQ pin is used as output in the suspend sequence */
goodix_free_irq(ts);
/* Output LOW on the INT pin for 5 ms */
@@ -739,7 +884,11 @@ static int __maybe_unused goodix_resume(struct device *dev)
if (ret)
return ret;
- return goodix_request_irq(ts);
+ ret = goodix_request_irq(ts);
+ if (ret)
+ return ret;
+
+ return goodix_enable_esd(ts);
}
static SIMPLE_DEV_PM_OPS(goodix_pm_ops, goodix_suspend, goodix_resume);
@@ -773,6 +922,7 @@ MODULE_DEVICE_TABLE(of, goodix_of_match);
static struct i2c_driver goodix_ts_driver = {
.probe = goodix_ts_probe,
+ .remove = goodix_ts_remove,
.id_table = goodix_ts_id,
.driver = {
.name = "Goodix-TS",
--
1.9.1
prev parent reply other threads:[~2015-06-29 16:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-29 16:28 [PATCH v3 0/5] Goodix touchscreen enhancements Irina Tirdea
2015-06-29 16:28 ` [PATCH v3 1/5] Input: goodix - reset device at init Irina Tirdea
2015-06-30 15:56 ` Bastien Nocera
2015-07-30 11:27 ` Tirdea, Irina
2015-09-09 17:02 ` Bastien Nocera
2015-09-10 14:04 ` Tirdea, Irina
2015-09-25 14:44 ` Bastien Nocera
2015-09-25 21:04 ` Tirdea, Irina
2015-09-29 2:04 ` Bastien Nocera
2015-09-29 17:47 ` Tirdea, Irina
2015-09-30 11:15 ` Bastien Nocera
2015-09-30 14:01 ` Carlos Garnacho
2015-10-01 14:42 ` Tirdea, Irina
2015-06-29 16:28 ` [PATCH v3 2/5] Input: goodix - write configuration data to device Irina Tirdea
2015-06-29 16:28 ` [PATCH v3 3/5] Input: goodix - add power management support Irina Tirdea
2015-06-30 15:56 ` Bastien Nocera
2015-07-30 11:32 ` Tirdea, Irina
2015-06-29 16:28 ` [PATCH v3 4/5] Input: goodix - use goodix_i2c_write_u8 instead of i2c_master_send Irina Tirdea
2015-06-29 16:28 ` Irina Tirdea [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435595304-4840-6-git-send-email-irina.tirdea@intel.com \
--to=irina.tirdea@intel.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=galak@codeaurora.org \
--cc=hadess@hadess.net \
--cc=ijc+devicetree@hellion.org.uk \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pawel.moll@arm.com \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®