From patchwork Wed Dec 15 08:12:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "sim.chinyeow" X-Patchwork-Id: 412681 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBF8CShO017807 for ; Wed, 15 Dec 2010 08:12:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752869Ab0LOIM1 (ORCPT ); Wed, 15 Dec 2010 03:12:27 -0500 Received: from mail-gx0-f180.google.com ([209.85.161.180]:36996 "EHLO mail-gx0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752540Ab0LOIM1 (ORCPT ); Wed, 15 Dec 2010 03:12:27 -0500 Received: by gxk19 with SMTP id 19so1082455gxk.11 for ; Wed, 15 Dec 2010 00:12:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer; bh=DU8iGz3GbbCfZMZMXpAKA2gFKbFmCc0x3wAbfiq/vlI=; b=DBQvZfFkkqvDMemtZ1iRBrMF0SqJV9D4j8d8IKig7TZU7PU4T8sEpDPHlL3Pzj93Ai UTeQaD50Fx6mWmntj13Hg58nnk5kKOYnXO2NdNkBj7et7hoPDediRBzGCbxcgwhF59xI 3VaEax4J9/gf2oe22za2F61UgRcCaF/GVENuc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; b=HMOIrdX/olCDWI++NBTNb5j6jKgjdJLvNvEe//ayDPZQAChJNLQqNntn/MlyMWiw/r Qj/EKJpaSE5razmWxWZ4Nsp2ZM14hTVZ84DpzZK8/Vzf9520djKeSn4FMGXIKvoPUTWZ 0L6F7V36v8tT80yYoUc9mE/F8p69Swh+esSlI= Received: by 10.150.195.4 with SMTP id s4mr9632709ybf.277.1292400744716; Wed, 15 Dec 2010 00:12:24 -0800 (PST) Received: from abacus.renesas.com (49.14.32.202.bf.2iij.net [202.32.14.49]) by mx.google.com with ESMTPS id k1sm684313ybj.0.2010.12.15.00.12.22 (version=SSLv3 cipher=RC4-MD5); Wed, 15 Dec 2010 00:12:24 -0800 (PST) From: chinyeow.sim.xt@renesas.com To: tsoni@codeaurora.org, dmitry.torokhov@gmail.com, rydberg@euromail.se, linux-input@vger.kernel.org Cc: chinyeow.sim.xt@renesas.com Subject: [PATCH v3] Input: add ST1232 touchscreen controller driver. Date: Wed, 15 Dec 2010 17:12:08 +0900 Message-Id: <1292400728-15521-1-git-send-email-chinyeow.sim.xt@renesas.com> X-Mailer: git-send-email 1.7.2.3 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Wed, 15 Dec 2010 08:12:30 +0000 (UTC) diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 06ea8da..3ca7700 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -681,4 +681,15 @@ config TOUCHSCREEN_STMPE To compile this driver as a module, choose M here: the module will be called stmpe-ts. +config TOUCHSCREEN_ST1232 + tristate "Sitronix ST1232 touchscreen controllers" + depends on I2C + help + Say Y here if you want to support Sitronix ST1232 + touchscreen controller. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called st1232_ts. endif diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 7cc1b4f..718bcc8 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o +obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c new file mode 100644 index 0000000..92457bc --- /dev/null +++ b/drivers/input/touchscreen/st1232.c @@ -0,0 +1,274 @@ +/* + * ST1232 Touchscreen Controller Driver + * + * Copyright (C) 2010 Renesas Solutions Corp. + * Tony SIM + * + * Using code from: + * - android.git.kernel.org: projects/kernel/common.git: synaptics_i2c_rmi.c + * Copyright (C) 2007 Google, Inc. + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include + +#define ST1232_TS_NAME "st1232-ts" + +#define MIN_X 0x00 +#define MIN_Y 0x00 +#define MAX_X 0x31f /* (800 - 1) */ +#define MAX_Y 0x1df /* (480 - 1) */ +#define MAX_AREA 0xff +#define MAX_FINGERS 2 + +struct st1232_ts_finger { + uint8_t is_valid; + uint16_t x; + uint16_t y; + uint8_t t; +}; + +struct st1232_ts_data { + struct i2c_client *client; + struct input_dev *input_dev; + struct delayed_work work; + struct st1232_ts_finger finger[MAX_FINGERS]; +}; + +static int st1232_ts_read_data(struct st1232_ts_data *ts) +{ + int ret; + struct i2c_msg msg[2]; + uint8_t start_reg; + uint8_t buf[10]; + struct st1232_ts_finger *finger = ts->finger; + + /* read touchscreen data from ST1232 */ + msg[0].addr = ts->client->addr; + msg[0].flags = 0; + msg[0].len = 1; + msg[0].buf = &start_reg; + start_reg = 0x10; + + msg[1].addr = ts->client->addr; + msg[1].flags = I2C_M_RD; + msg[1].len = sizeof(buf); + msg[1].buf = buf; + + ret = i2c_transfer(ts->client->adapter, msg, 2); + if (ret < 0) + return ret; + + /* get valid bit */ + finger[0].is_valid = buf[2] >> 7; + finger[1].is_valid = buf[5] >> 7; + + /* get xy coordinate */ + if (finger[0].is_valid) { + finger[0].x = ((buf[2] & 0x0070) << 4) | buf[3]; + finger[0].y = ((buf[2] & 0x0007) << 8) | buf[4]; + finger[0].t = buf[8]; + } + + if (finger[1].is_valid) { + finger[1].x = ((buf[5] & 0x0070) << 4) | buf[6]; + finger[1].y = ((buf[5] & 0x0007) << 8) | buf[7]; + finger[1].t = buf[9]; + } + + return 0; +} + +static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id) +{ + int i, ret, flg; + struct st1232_ts_data *ts = dev_id; + struct st1232_ts_finger *finger = ts->finger; + + ret = st1232_ts_read_data(ts); + if (ret < 0) + goto end; + + /* multi touch protocol */ + for (i = 0, flg = 0; i < MAX_FINGERS; i++) { + if (!finger[i].is_valid) + continue; + else + flg = 1; + + input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, + finger[i].t); + input_report_abs(ts->input_dev, ABS_MT_POSITION_X, finger[i].x); + input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, finger[i].y); + input_mt_sync(ts->input_dev); + } + + /* SYN_MT_REPORT only if no contact */ + if (!flg) + input_mt_sync(ts->input_dev); + + /* SYN_REPORT */ + input_sync(ts->input_dev); + +end: + return IRQ_HANDLED; +} + +static int __devinit st1232_ts_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct st1232_ts_data *ts; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(&client->dev, "need I2C_FUNC_I2C\n"); + return -EIO; + } + + ts = kzalloc(sizeof(struct st1232_ts_data), GFP_KERNEL); + if (!ts) { + ret = -ENOMEM; + goto err; + } + + ts->client = client; + i2c_set_clientdata(client, ts); + + ts->input_dev = input_allocate_device(); + if (!ts->input_dev) { + ret = -ENOMEM; + dev_err(&client->dev, "Failed to allocate input device\n"); + goto err_free_mem; + } + ts->input_dev->name = "st1232-touchscreen"; + + __set_bit(EV_SYN, ts->input_dev->evbit); + __set_bit(EV_KEY, ts->input_dev->evbit); + __set_bit(EV_ABS, ts->input_dev->evbit); + + input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, + 0, MAX_AREA, 0, 0); + input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, + MIN_X, MAX_X, 0, 0); + input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, + MIN_Y, MAX_Y, 0, 0); + + ret = input_register_device(ts->input_dev); + if (ret) { + dev_err(&client->dev, "Unable to register %s input device\n", + ts->input_dev->name); + goto err_free_input_device; + } + + ret = request_threaded_irq(client->irq, NULL, st1232_ts_irq_handler, + IRQF_ONESHOT, client->name, ts); + if (ret) { + dev_err(&client->dev, "Failed to register interrupt\n"); + goto err_free_input_device; + } + + device_init_wakeup(&client->dev, 1); + + return 0; + +err_free_input_device: + input_free_device(ts->input_dev); +err_free_mem: + kfree(ts); +err: + return ret; +} + +static int __devexit st1232_ts_remove(struct i2c_client *client) +{ + struct st1232_ts_data *ts = i2c_get_clientdata(client); + + device_init_wakeup(&client->dev, 0); + free_irq(client->irq, ts); + input_unregister_device(ts->input_dev); + kfree(ts); + + return 0; +} + +#ifdef CONFIG_PM +static int st1232_ts_suspend(struct device *dev) +{ + struct st1232_ts_data *ts = dev_get_drvdata(dev); + struct i2c_client *client = ts->client; + + if (device_may_wakeup(&client->dev)) + enable_irq_wake(client->irq); + else + disable_irq(client->irq); + + return 0; +} + +static int st1232_ts_resume(struct device *dev) +{ + struct st1232_ts_data *ts = dev_get_drvdata(dev); + struct i2c_client *client = ts->client; + + if (device_may_wakeup(&client->dev)) + disable_irq_wake(client->irq); + else + enable_irq(client->irq); + + return 0; +} + +static const struct dev_pm_ops st1232_ts_pm_ops = { + .suspend = st1232_ts_suspend, + .resume = st1232_ts_resume, +}; +#endif + +static const struct i2c_device_id st1232_ts_id[] = { + { ST1232_TS_NAME, 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, st1232_ts_id); + +static struct i2c_driver st1232_ts_driver = { + .probe = st1232_ts_probe, + .remove = __devexit_p(st1232_ts_remove), + .id_table = st1232_ts_id, + .driver = { + .name = ST1232_TS_NAME, + .owner = THIS_MODULE, +#ifdef CONFIG_PM + .pm = &st1232_ts_pm_ops, +#endif + }, +}; + +static int __init st1232_ts_init(void) +{ + return i2c_add_driver(&st1232_ts_driver); +} +module_init(st1232_ts_init); + +static void __exit st1232_ts_exit(void) +{ + i2c_del_driver(&st1232_ts_driver); +} +module_exit(st1232_ts_exit); + +MODULE_AUTHOR("Tony SIM "); +MODULE_DESCRIPTION("SITRONIX ST1232 Touchscreen Controller Driver"); +MODULE_LICENSE("GPL");