@@ -0,0 +1,269 @@
+/* drivers/input/touchscreen/pixcir_i2c_ts.c
+ *
+ * Copyright (C) 2010-2011 Pixcir, Inc.
+ * V1.0
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
+ */
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/i2c.h>
+#include "pixcir_i2c_ts.h"
+
+struct pixcir_i2c_ts_data {
+ struct i2c_client *client;
+ struct input_dev *input;
+ wait_queue_head_t wait;
+ const struct pixcir_i2c_ts_platform *chip;
+ unsigned int attb_pin;
+ int irq;
+};
+
+static int pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
+{
+ struct pixcir_i2c_ts_data *tsdata = data;
+
+ u8 touching, oldtouching;
+ u16 posx1, posy1, posx2, posy2;
+ u8 rdbuf[10], wrbuf[1];
+ int ret;
+
+ memset(wrbuf, 0, sizeof(wrbuf));
+ memset(rdbuf, 0, sizeof(rdbuf));
+
+ wrbuf[0] = 0;
+ ret = i2c_master_send(tsdata->client, wrbuf, 1);
+ if (ret != 1) {
+ dev_err(&tsdata->client->dev, "Unable to write to i2c touchscreen!\n");
+ goto out;
+ }
+
+ ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
+ if (ret != sizeof(rdbuf)) {
+ dev_err(&tsdata->client->dev, "Unable to read i2c page!\n");
+ goto out;
+ }
+
+ touching = rdbuf[0];
+ oldtouching = rdbuf[1];
+ posx1 = ((rdbuf[3] << 8) | rdbuf[2]);
+ posy1 = ((rdbuf[5] << 8) | rdbuf[4]);
+ posx2 = ((rdbuf[7] << 8) | rdbuf[6]);
+ posy2 = ((rdbuf[9] << 8) | rdbuf[8]);
+
+ input_report_key(tsdata->input, BTN_TOUCH, touching);
+
+ if (touching == 1) {
+ input_report_abs(tsdata->input, ABS_X, posx1);
+ input_report_abs(tsdata->input, ABS_Y, posy1);
+ }
+
+ if (touching == 2) {
+ input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx1);
+ input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy1);
+ input_mt_sync(tsdata->input);
+
+ input_report_abs(tsdata->input, ABS_MT_POSITION_X, posx2);
+ input_report_abs(tsdata->input, ABS_MT_POSITION_Y, posy2);
+ input_mt_sync(tsdata->input);
+ } else
+ input_mt_sync(tsdata->input);
+ input_sync(tsdata->input);
+
+ return 0;
+
+out:
+ return -EINVAL;
+}
+
+static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)
+{
+ struct pixcir_i2c_ts_data *tsdata = dev_id;
+
+ do {
+ pixcir_ts_poscheck(tsdata);
+ tsdata->attb_pin = tsdata->chip->attb_read_val();
+ if (tsdata->attb_pin == ATTB_PIN_LOW)
+ wait_event_timeout(tsdata->wait, TRUE,
+ msecs_to_jiffies(20));
+ } while (!tsdata->attb_pin);
+
+ return IRQ_HANDLED;
+}
+
+static void pixcir_ts_close(struct input_dev *dev)
+{
+
+}
+
+static int pixcir_i2c_ts_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct pixcir_i2c_ts_data *tsdata;
+ struct input_dev *input;
+ const struct pixcir_i2c_ts_platform *pdata =
+ client->dev.platform_data;
+ int error;
+
+ if (!pdata) {
+ dev_err(&client->dev, "platform data not defined\n");
+ return -EINVAL;
+ }
+
+ tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL);
+ if (!tsdata) {
+ dev_err(&client->dev, "Failed to allocate driver data!\n");
+ error = -ENOMEM;
+ dev_set_drvdata(&client->dev, NULL);
+ return error;
+ }
+
+ dev_set_drvdata(&client->dev, tsdata);
+
+ input = input_allocate_device();
+ if (!input) {
+ dev_err(&client->dev, "Failed to allocate input device!\n");
+ error = -ENOMEM;
+ input_free_device(input);
+ kfree(tsdata);
+ }
+
+ init_waitqueue_head(&tsdata->wait);
+
+ input->name = client->name;
+ input->id.bustype = BUS_I2C;
+ input->dev.parent = &client->dev;
+
+ input->close = pixcir_ts_close;
+
+ input_set_drvdata(input, tsdata);
+
+ tsdata->client = client;
+ tsdata->input = input;
+ tsdata->chip = pdata;
+ tsdata->irq = client->irq;
+
+ set_bit(EV_SYN, input->evbit);
+ set_bit(EV_KEY, input->evbit);
+ set_bit(EV_ABS, input->evbit);
+ set_bit(BTN_TOUCH, input->keybit);
+ input_set_abs_params(input, ABS_X, 0, pdata->ts_x_max, 0, 0);
+ input_set_abs_params(input, ABS_Y, 0, pdata->ts_y_max, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_X, 0, pdata->ts_x_max, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_Y, 0, pdata->ts_y_max, 0, 0);
+
+ if (input_register_device(input)) {
+ input_free_device(input);
+ kfree(tsdata);
+ }
+
+ if (request_threaded_irq(tsdata->irq, NULL, pixcir_ts_isr,
+ IRQF_TRIGGER_FALLING, client->name, tsdata)) {
+ dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
+ input_unregister_device(input);
+ input = NULL;
+ }
+
+ device_init_wakeup(&client->dev, 1);
+
+ return 0;
+}
+
+static int pixcir_i2c_ts_remove(struct i2c_client *client)
+{
+ struct pixcir_i2c_ts_data *tsdata;
+
+ tsdata = i2c_get_clientdata(client);
+ wake_up(&tsdata->wait);
+ free_irq(tsdata->irq, tsdata);
+ input_unregister_device(tsdata->input);
+ kfree(tsdata);
+ dev_set_drvdata(&client->dev, NULL);
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int pixcir_i2c_ts_suspend(struct i2c_client *client,