b/drivers/input/touchscreen/Kconfig
@@ -510,6 +510,17 @@ config TOUCHSCREEN_W90X900
     To compile this driver as a module, choose M here: the
     module will be called w90p910_ts.
+config TOUCHSCREEN_DTS413
+ Â Â Â tristate "DTS413 based touchscreens"
+ Â Â Â depends on I2C
+ Â Â Â help
+ Â Â Â Â Say Y here if you have a DTS413 based touchscreen.
+
+ Â Â Â Â If unsure, say N.
+
+ Â Â Â Â To compile this driver as a module, choose M here: the
+ Â Â Â Â module will be called dts413.
+
 config TOUCHSCREEN_PCAP
    tristate "Motorola PCAP touchscreen"
    depends on EZX_PCAP
b/drivers/input/touchscreen/Makefile
@@ -40,4 +40,6 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_ATMEL) Â Â Â Â +=
atmel-wm97xx.o
 obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE)   += mainstone-wm97xx.o
 obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE)    += zylonite-wm97xx.o
 obj-$(CONFIG_TOUCHSCREEN_W90X900)    += w90p910_ts.o
+obj-$(CONFIG_TOUCHSCREEN_DTS413) Â Â Â += dts413.o
 obj-$(CONFIG_TOUCHSCREEN_PCAP)     += pcap_ts.o
+
b/drivers/input/touchscreen/dts413.c
new file mode 100644
@@ -0,0 +1,286 @@
+/*
+ * drivers/input/touchscreen/dts413.c
+ *
+ * Copyright (c) 2009 Iskraemeco d.d.
+ * Â Â Jernej Turnsek <jernej.turnsek@iskraemeco.si>
+ *
+ * Using code from:
+ * Â - migor_ts.c
+ * Copyright (c) 2008 Magnus Damm
+ * Copyright (c) 2007 Ujjwal Pande <ujjwal@kenati.com>,
+ * Â Kenati Technologies Pvt Ltd.
+ *
+ * Â This program is free software; you can redistribute it and/or modify
+ * Â it under the terms of the GNU General Public License version 2 as
+ * Â published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/i2c.h>
+#include <linux/timer.h>
+#include <linux/workqueue.h>
+
+
+#define     MAX_11BIT        ((1 << 11) - 1)
+
+#define EVENT_PENDOWN Â 1
+#define EVENT_PENUP Â Â Â Â Â Â 0
+
+/**
+ * struct dts413 - device structure
+ * @client: the i2c client,
+ * @input: the input device,
+ * @work: workqueue,
+ * @irq: irq number.
+ *
+ * Structure for holding the internal context of a driver.
+ */
+struct dts413 {
+ Â Â Â struct i2c_client *client;
+ Â Â Â struct input_dev *input;
+ Â Â Â struct work_struct work;
+ Â Â Â int irq;
+};
+
+/**
+ * dts413_poscheck() - function for position checking
+ * @work: workqueue.
+ *
+ * DTS413 report packet:
+ * Â Â Â Â MSB Â Â Â Â Â Â Â Â Â Â Â Â LSB
+ * BYTE1:| 1 | R | R | R | R | R | R | S |
+ * BYTE2:| 0 | 0 | 0 | 0 |A10| A9| A8| A7|
+ * BYTE3:| 0 | A6| A5| A4| A3| A2| A1| A0|
+ * BYTE4:| 0 | 0 | 0 | 0 |B10| B9| B8| B7|
+ * BYTE5:| 0 | B6| B5| B4| B3| B2| B1| B0|
+ * BYTE6:| 0 | P6| P5| P4| P3| P2| P1| P0|
+ *
+ * S - status
+ * A10-A0 - 11 bits of 1st direction raw data
+ * B10-B0 - 11 bits of 2st direction raw data
+ * P6-P0 - 7 bits of finger pressure
+ * Please be aware that A nad B just represent 2 resolution directions
+ * of the touch panel. The reported coordinates are (0~2047,0-2047),
+ * the bottom left is (0,0).
+ */
+static void dts413_poscheck(struct work_struct *work)
+{
+ Â Â Â struct dts413 *priv = container_of(work,
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct dts413,
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â work);
+ Â Â Â unsigned short xpos, ypos;
+ Â Â Â u_int8_t event, speed;
+ Â Â Â u_int8_t buf[6];
+
+ Â Â Â memset(buf, 0, sizeof(buf));
+
+ Â Â Â /* now do page read */
+ Â Â Â if (i2c_master_recv(priv->client, buf, sizeof(buf)) != sizeof(buf)) {
+ Â Â Â Â Â Â Â dev_err(&priv->client->dev, "Unable to read i2c page\n");
+ Â Â Â Â Â Â Â goto out;
+ Â Â Â }
+
+ Â Â Â event = (buf[0] & 0x01) ? 1 : 0;
+ Â Â Â xpos = (unsigned short)(buf[2] & 0x7f) |
+ Â Â Â Â Â Â Â Â Â Â Â ((unsigned short)(buf[1] & 0x0f) << 7);
+ Â Â Â ypos = (unsigned short)(buf[4] & 0x7f) |
+ Â Â Â Â Â Â Â Â Â Â Â ((unsigned short)(buf[3] & 0x0f) << 7);
+ Â Â Â speed = (buf[5] & 0x7f);
+
+ Â Â Â if (event == EVENT_PENDOWN) {
+ Â Â Â Â Â Â Â input_report_key(priv->input, BTN_TOUCH, 1);
+ Â Â Â Â Â Â Â input_report_abs(priv->input, ABS_X, xpos);
+ Â Â Â Â Â Â Â input_report_abs(priv->input, ABS_Y, 2048 - ypos);
+ Â Â Â Â Â Â Â input_report_abs(priv->input, ABS_PRESSURE, 1);
+ Â Â Â Â Â Â Â input_sync(priv->input);
+ Â Â Â } else if (event == EVENT_PENUP) {
+ Â Â Â Â Â Â Â input_report_key(priv->input, BTN_TOUCH, 0);
+ Â Â Â Â Â Â Â input_report_abs(priv->input, ABS_PRESSURE, 0);
+ Â Â Â Â Â Â Â input_sync(priv->input);
+ Â Â Â }
+ out:
+ Â Â Â enable_irq(priv->irq);
+}
+
+/**
+ * dts413_isr() - interrupt service routine
+ * @irg: irq number.
+ * @dev_id: dts413 device.
+ *
+ * The touch screen controller chip is hooked up to the cpu
+ * using i2c and a single interrupt line. The interrupt line
+ * is pulled low whenever someone taps the screen. To deassert
+ * the interrupt line we need to acknowledge the interrupt by
+ * communicating with the controller over the slow i2c bus.
+ *
+ * We can't acknowledge from interrupt context since the i2c
+ * bus controller may sleep, so we just disable the interrupt
+ * here and handle the acknowledge using delayed work.
+ */
+static irqreturn_t dts413_isr(int irq, void *dev_id)
+{
+ Â Â Â struct dts413 *priv = dev_id;
+
+ Â Â Â disable_irq_nosync(irq);
+ Â Â Â schedule_work(&priv->work);
+
+ Â Â Â return IRQ_HANDLED;
+}
+
+static int dts413_open(struct input_dev *dev)
+{
+ Â Â Â return 0;
+}
+
+static void dts413_close(struct input_dev *dev)
+{
+ Â Â Â struct dts413 *priv = input_get_drvdata(dev);
+
+ Â Â Â disable_irq(priv->irq);
+
+ Â Â Â cancel_work_sync(&priv->work);
+
+ Â Â Â enable_irq(priv->irq);
+}
+
+static int dts413_probe(struct i2c_client *client,
+ Â Â Â Â Â Â Â Â Â Â Â const struct i2c_device_id *idp)
+{
+ Â Â Â struct dts413 *priv;
+ Â Â Â struct input_dev *input;
+ Â Â Â int error;
+
+ Â Â Â priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ Â Â Â if (!priv) {
+ Â Â Â Â Â Â Â dev_err(&client->dev, "failed to allocate driver data\n");
+ Â Â Â Â Â Â Â error = -ENOMEM;
+ Â Â Â Â Â Â Â goto err0;
+ Â Â Â }
+
+ Â Â Â dev_set_drvdata(&client->dev, priv);
+
+ Â Â Â input = input_allocate_device();
+ Â Â Â if (!input) {
+ Â Â Â Â Â Â Â dev_err(&client->dev, "Failed to allocate input device.\n");
+ Â Â Â Â Â Â Â error = -ENOMEM;
+ Â Â Â Â Â Â Â goto err1;
+ Â Â Â }
+
+ Â Â Â input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+ Â Â Â input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
+
+ Â Â Â input_set_abs_params(input, ABS_X, 0, MAX_11BIT, 0, 0);
+ Â Â Â input_set_abs_params(input, ABS_Y, 0, MAX_11BIT, 0, 0);
+ Â Â Â input_set_abs_params(input, ABS_PRESSURE, 0, 0, 0, 0);
+
+ Â Â Â input->name = client->name;
+ Â Â Â input->id.bustype = BUS_I2C;
+ Â Â Â input->dev.parent = &client->dev;
+
+ Â Â Â input->open = dts413_open;
+ Â Â Â input->close = dts413_close;
+
+ Â Â Â input_set_drvdata(input, priv);
+
+ Â Â Â priv->client = client;
+ Â Â Â priv->input = input;
+ Â Â Â INIT_WORK(&priv->work, dts413_poscheck);
+ Â Â Â priv->irq = client->irq;
+
+ Â Â Â error = input_register_device(input);
+ Â Â Â if (error)
+ Â Â Â Â Â Â Â goto err1;
+
+ Â Â Â error = request_irq(priv->irq, dts413_isr,
IRQF_TRIGGER_FALLING/*IRQF_TRIGGER_LOW*/,
+ Â Â Â Â Â Â Â Â Â Â Â Â Â client->name, priv);
+ Â Â Â if (error) {
+ Â Â Â Â Â Â Â dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
+ Â Â Â Â Â Â Â goto err2;
+ Â Â Â }
+
+ Â Â Â device_init_wakeup(&client->dev, 1);
+ Â Â Â return 0;
+
+ err2:
+ Â Â Â input_unregister_device(input);
+ Â Â Â input = NULL; /* so we dont try to free it below */
+ err1:
+ Â Â Â input_free_device(input);
+ Â Â Â kfree(priv);
+ err0:
+ Â Â Â dev_set_drvdata(&client->dev, NULL);
+ Â Â Â return error;
+}
+
+static int dts413_remove(struct i2c_client *client)
+{
+ Â Â Â struct dts413 *priv = dev_get_drvdata(&client->dev);
+
+ Â Â Â free_irq(priv->irq, priv);
+ Â Â Â input_unregister_device(priv->input);
+ Â Â Â kfree(priv);
+
+ Â Â Â dev_set_drvdata(&client->dev, NULL);
+
+ Â Â Â return 0;
+}
+
+static int dts413_suspend(struct i2c_client *client, pm_message_t mesg)
+{
+ Â Â Â struct dts413 *priv = dev_get_drvdata(&client->dev);
+
+ Â Â Â if (device_may_wakeup(&client->dev))
+ Â Â Â Â Â Â Â enable_irq_wake(priv->irq);
+
+ Â Â Â return 0;
+}
+
+static int dts413_resume(struct i2c_client *client)
+{
+ Â Â Â struct dts413 *priv = dev_get_drvdata(&client->dev);
+
+ Â Â Â if (device_may_wakeup(&client->dev))
+ Â Â Â Â Â Â Â disable_irq_wake(priv->irq);
+
+ Â Â Â return 0;
+}
+
+static struct i2c_device_id dts413_idtable[] = {
+ Â Â Â { "dts413", 0 },
+ Â Â Â { }
+};
+
+MODULE_DEVICE_TABLE(i2c, dts413_idtable);
+
+static struct i2c_driver dts413_driver = {
+ Â Â Â .driver = {
+        .owner  = THIS_MODULE,
+        .name  = "dts413"
+ Â Â Â },
+    .id_table    = dts413_idtable,
+    .probe      = dts413_probe,
+    .remove     = __devexit_p(dts413_remove),
+ Â Â Â .suspend = dts413_suspend,
+ Â Â Â .resume = dts413_resume,
+};
+
+static int __init dts413_init(void)
+{
+ Â Â Â return i2c_add_driver(&dts413_driver);
+}
+
+static void __exit dts413_exit(void)
+{
+ Â Â Â i2c_del_driver(&dts413_driver);
+}
+
+module_init(dts413_init);
+module_exit(dts413_exit);
+
+MODULE_AUTHOR("Jernej Turnsek <jernej.turnsek@iskraemeco.si>");
+MODULE_DESCRIPTION("DTS413 Touch Screen Controller driver");