summaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorAndrew Tran <atran@nvidia.com>2014-03-18 13:46:33 -0700
committerSeema Khowala <seemaj@nvidia.com>2014-04-23 14:07:15 -0700
commite9a9b3e6e2b44261abd02c27c6d244574011204d (patch)
treefec8664048bbb073515cdc87a45559b6f1c8f5a3 /drivers/input
parent61156d6d4c44de184191c21e3df8f329afba398c (diff)
input: touch: maxim: add device tree support
-update maxim touch driver to support device tree. -add sample maxim touch device tree in documentation Bug 1468560 Change-Id: Id7a99ca9bdeb53f7d817e33874dac9bca48965a9 Signed-off-by: Andrew Tran <atran@nvidia.com> Reviewed-on: http://git-master/r/383999 (cherry picked from commit 86384c3e1db348509887c7bbdbe9f3e3c5be8941) Reviewed-on: http://git-master/r/383268 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Mitch Luban <mluban@nvidia.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/touchscreen/maxim_sti.c185
1 files changed, 185 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/maxim_sti.c b/drivers/input/touchscreen/maxim_sti.c
index abb91ee42f56..6100bd827ac0 100644
--- a/drivers/input/touchscreen/maxim_sti.c
+++ b/drivers/input/touchscreen/maxim_sti.c
@@ -28,6 +28,12 @@
#include <linux/regulator/consumer.h>
#include <linux/maxim_sti.h>
#include <asm/byteorder.h> /* MUST include this header to get byte order */
+#ifdef CONFIG_OF
+#include <linux/gpio.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#endif
#define CREATE_TRACE_POINTS
#include <trace/events/touchscreen_maxim.h>
@@ -795,6 +801,159 @@ err_null_regulator:
dev_warn(&dd->spi->dev, "Failed to init regulators\n");
}
+#ifdef CONFIG_OF
+#define MAXIM_STI_GPIO_ERROR(ret, gpio, op) \
+{ \
+ if (ret < 0) { \
+ pr_err("%s: GPIO %d %s failed (%d)\n", __func__, gpio, op, \
+ ret); \
+ return ret; \
+ } \
+}
+
+
+int maxim_sti_gpio_init(struct maxim_sti_pdata *pdata, bool init)
+{
+ int ret;
+
+ if (init) {
+ ret = gpio_request(pdata->gpio_irq, "maxim_sti_irq");
+ MAXIM_STI_GPIO_ERROR(ret, pdata->gpio_irq, "request");
+ ret = gpio_direction_input(pdata->gpio_irq);
+ MAXIM_STI_GPIO_ERROR(ret, pdata->gpio_irq, "direction");
+
+ ret = gpio_request(pdata->gpio_reset, "maxim_sti_reset");
+ MAXIM_STI_GPIO_ERROR(ret, pdata->gpio_reset, "request");
+ ret = gpio_direction_output(pdata->gpio_reset,
+ pdata->default_reset_state);
+ MAXIM_STI_GPIO_ERROR(ret, pdata->gpio_reset, "direction");
+ } else {
+ gpio_free(pdata->gpio_irq);
+ gpio_free(pdata->gpio_reset);
+ }
+
+ return 0;
+}
+
+void maxim_sti_gpio_reset(struct maxim_sti_pdata *pdata, int value)
+{
+ gpio_set_value(pdata->gpio_reset, !!value);
+}
+
+int maxim_sti_gpio_irq(struct maxim_sti_pdata *pdata)
+{
+ return gpio_get_value(pdata->gpio_irq);
+}
+
+/****************************************************************************\
+* Device Tree Support
+\****************************************************************************/
+
+static int maxim_parse_dt(struct device *dev, struct maxim_sti_pdata *pdata)
+{
+ struct device_node *np = dev->of_node;
+ u32 val;
+ const char *str;
+ int ret;
+
+
+ ret = of_property_read_u32(np, "maxim_sti,reset-gpio",
+ &pdata->gpio_reset);
+ if (ret) {
+ dev_err(dev, "%s: unable to read reset-gpio (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+
+ ret = of_property_read_u32(np, "interrupts", &pdata->gpio_irq);
+ if (ret) {
+ dev_err(dev, "%s: unable to read irq-gpio (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+
+ ret = of_property_read_u32(np, "maxim_sti,nl_mc_groups", &val);
+ if (ret) {
+ dev_err(dev, "%s: unable to read nl_mc_groups (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->nl_mc_groups = (u8)val;
+
+ ret = of_property_read_u32(np, "maxim_sti,chip_access_method", &val);
+ if (ret) {
+ dev_err(dev, "%s: unable to read chip_access_method (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->chip_access_method = (u8)val;
+
+ ret = of_property_read_u32(np, "maxim_sti,default_reset_state", &val);
+ if (ret) {
+ dev_err(dev, "%s: unable to read default_reset_state (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->default_reset_state = (u8)val;
+
+ ret = of_property_read_u32(np, "maxim_sti,tx_buf_size", &val);
+ if (ret) {
+ dev_err(dev, "%s: unable to read tx_buf_size (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->tx_buf_size = (u16)val;
+
+ ret = of_property_read_u32(np, "maxim_sti,rx_buf_size", &val);
+ if (ret) {
+ dev_err(dev, "%s: unable to read rx_buf_size (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->rx_buf_size = (u16)val;
+
+ ret = of_property_read_string(np, "maxim_sti,touch_fusion", &str);
+ if (ret) {
+ dev_err(dev, "%s: unable to read touch_fusion location (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->touch_fusion = (char *)str;
+
+ ret = of_property_read_string(np, "maxim_sti,config_file", &str);
+ if (ret) {
+ dev_err(dev, "%s: unable to read config_file location (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->config_file = (char *)str;
+
+ ret = of_property_read_string(np, "maxim_sti,nl_family", &str);
+ if (ret) {
+ dev_err(dev, "%s: unable to read nl_family (%d)\n",
+ __func__, ret);
+ goto fail;
+ }
+ pdata->nl_family = (char *)str;
+
+ ret = of_property_read_string(np, "maxim_sti,fw_name", &str);
+ if (ret) {
+ dev_err(dev, "%s: unable to read fw_name (%d)\n",
+ __func__, ret);
+ }
+ pdata->fw_name = (char *)str;
+
+ pdata->init = maxim_sti_gpio_init;
+ pdata->reset = maxim_sti_gpio_reset;
+ pdata->irq = maxim_sti_gpio_irq;
+
+ return 0;
+
+fail:
+ return ret;
+}
+#endif
+
/****************************************************************************\
* Suspend/resume processing *
\****************************************************************************/
@@ -1824,6 +1983,22 @@ static int probe(struct spi_device *spi)
int ret, i;
void *ptr;
+#ifdef CONFIG_OF
+ if (pdata == NULL && spi->dev.of_node) {
+ pdata = devm_kzalloc(&spi->dev,
+ sizeof(struct maxim_sti_pdata), GFP_KERNEL);
+ if (!pdata) {
+ dev_err(&spi->dev, "failed to allocate memory\n");
+ return -ENOMEM;
+ }
+
+ ret = maxim_parse_dt(&spi->dev, pdata);
+ if (ret)
+ return ret;
+ spi->dev.platform_data = pdata;
+ }
+#endif
+
/* validate platform data */
if (pdata == NULL || pdata->init == NULL || pdata->reset == NULL ||
pdata->irq == NULL || pdata->touch_fusion == NULL ||
@@ -2035,6 +2210,13 @@ static const struct spi_device_id id[] = {
MODULE_DEVICE_TABLE(spi, id);
+#ifdef CONFIG_OF
+static struct of_device_id maxim_match_table[] = {
+ { .compatible = "maxim,maxim_sti",},
+ { },
+};
+#endif
+
static struct spi_driver driver = {
.probe = probe,
.remove = remove,
@@ -2042,6 +2224,9 @@ static struct spi_driver driver = {
.id_table = id,
.driver = {
.name = MAXIM_STI_NAME,
+#ifdef CONFIG_OF
+ .of_match_table = maxim_match_table,
+#endif
.owner = THIS_MODULE,
#if defined(CONFIG_PM_SLEEP) && DOUBLE_TAP
.pm = &pm_ops,