From patchwork Thu Jul 28 10:27:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 1015242 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6SASZN4028836 for ; Thu, 28 Jul 2011 10:28:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754877Ab1G1K2d (ORCPT ); Thu, 28 Jul 2011 06:28:33 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:60776 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754839Ab1G1K2c (ORCPT ); Thu, 28 Jul 2011 06:28:32 -0400 Received: by mail-wy0-f174.google.com with SMTP id 8so7448wyg.19 for ; Thu, 28 Jul 2011 03:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Ry5vSHilpJsQUDAmHyIHgP7k0GVj6w7hIhLuT4OpW4w=; b=fkoyAN/yM7kuGs80s6gtKwEr998FihTZV4GksGbJes+lgzgUbWSIqz0t0y/tmEP+Bb D6RA+4yiaTem7sxEOz7J/vHUTns61wFpY5Ybhp5TRB/8Q66MVxViukBIh0QU6bRntxFT GXwXXX8bnFU0nSQ4wty7VaPtM8Vnf/c9spZm8= Received: by 10.227.20.77 with SMTP id e13mr7368188wbb.60.1311848908224; Thu, 28 Jul 2011 03:28:28 -0700 (PDT) Received: from localhost.localdomain (211.Red-79-146-221.dynamicIP.rima-tde.net [79.146.221.211]) by mx.google.com with ESMTPS id h1sm568208wee.25.2011.07.28.03.28.26 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Jul 2011 03:28:27 -0700 (PDT) From: Javier Martinez Canillas Cc: Kevin McNeely , devel@linuxdriverproject.org, kernel-janitors@vger.kernel.org, linux-input@vger.kernel.org, Steve Kolokowsky , rydberg@euromail.se, Oleg Drokin , William Marone , Javier Martinez Canillas Subject: [PATCH 2/3] staging: cyttsp: Add Cypress TTSP G3 I2C Device Driver Date: Thu, 28 Jul 2011 12:27:41 +0200 Message-Id: <1311848862-24236-3-git-send-email-martinez.javier@gmail.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1311848862-24236-1-git-send-email-martinez.javier@gmail.com> References: <1311848862-24236-1-git-send-email-martinez.javier@gmail.com> To: unlisted-recipients:; (no To-header on input) 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.6 (demeter2.kernel.org [140.211.167.43]); Thu, 28 Jul 2011 10:28:35 +0000 (UTC) Cypress TTSP Gen3 I2C Device Driver. Provides i2c communications modules for the Cypress TTSP Gen3 MTDEV Core Driver. The original author of this driver is: Kevin McNeely Signed-off-by: Javier Martinez Canillas --- drivers/staging/cyttsp/Kconfig | 12 +++ drivers/staging/cyttsp/Makefile | 1 + drivers/staging/cyttsp/cyttsp_i2c.c | 188 +++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 0 deletions(-) create mode 100644 drivers/staging/cyttsp/cyttsp_i2c.c diff --git a/drivers/staging/cyttsp/Kconfig b/drivers/staging/cyttsp/Kconfig index 6849d3a..b1ffb2a 100644 --- a/drivers/staging/cyttsp/Kconfig +++ b/drivers/staging/cyttsp/Kconfig @@ -19,3 +19,15 @@ config TOUCHSCREEN_CYTTSP_CORE To compile this driver as a module, choose M here: the module will be called cyttsp_core. + +config TOUCHSCREEN_CYTTSP_I2C + tristate "Cypress TTSP i2c touchscreen" + depends on I2C && TOUCHSCREEN_CYTTSP_CORE + help + Say Y here if you have a Cypress TTSP touchscreen + connected to your system with an I2C interface. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called cyttsp-i2c. diff --git a/drivers/staging/cyttsp/Makefile b/drivers/staging/cyttsp/Makefile index d1b250f..9101dc9 100644 --- a/drivers/staging/cyttsp/Makefile +++ b/drivers/staging/cyttsp/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o +obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o diff --git a/drivers/staging/cyttsp/cyttsp_i2c.c b/drivers/staging/cyttsp/cyttsp_i2c.c new file mode 100644 index 0000000..d79c6a7 --- /dev/null +++ b/drivers/staging/cyttsp/cyttsp_i2c.c @@ -0,0 +1,188 @@ +/* + * Source for: + * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver. + * For use with Cypress Txx3xx parts. + * Supported parts include: + * CY8CTST341 + * CY8CTMA340 + * + * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2, and only version 2, as published by the + * Free Software Foundation. + * + * 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 program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contact Cypress Semiconductor at www.cypress.com + * + */ + +#include "cyttsp_core.h" + +#include +#include + +#define CY_I2C_DATA_SIZE 128 + +struct cyttsp_i2c { + struct cyttsp_bus_ops ops; + struct i2c_client *client; + void *ttsp_client; + u8 wr_buf[CY_I2C_DATA_SIZE]; +}; + +static s32 ttsp_i2c_read_block_data(void *handle, u8 addr, + u8 length, void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c, ops); + int retval = 0; + + retval = i2c_master_send(ts->client, &addr, 1); + if (retval < 0) + return retval; + + retval = i2c_master_recv(ts->client, values, length); + + return (retval < 0) ? retval : 0; +} + +static s32 ttsp_i2c_write_block_data(void *handle, u8 addr, + u8 length, const void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c, ops); + int retval; + + ts->wr_buf[0] = addr; + memcpy(&ts->wr_buf[1], values, length); + + retval = i2c_master_send(ts->client, ts->wr_buf, length+1); + + return (retval < 0) ? retval : 0; +} + +static s32 ttsp_i2c_tch_ext(void *handle, void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c, ops); + int retval = 0; + + /* + * TODO: Add custom touch extension handling code here + * set: retval < 0 for any returned system errors, + * retval = 0 if normal touch handling is required, + * retval > 0 if normal touch handling is *not* required + */ + if (!ts || !values) + retval = -EINVAL; + + return retval; +} + +static int __devinit cyttsp_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct cyttsp_i2c *ts; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -EIO; + + /* allocate and clear memory */ + ts = kzalloc(sizeof(*ts), GFP_KERNEL); + if (!ts) { + dev_dbg(&client->dev, "%s: Error, kzalloc.\n", __func__); + return -ENOMEM; + } + + /* register driver_data */ + ts->client = client; + i2c_set_clientdata(client, ts); + ts->ops.write = ttsp_i2c_write_block_data; + ts->ops.read = ttsp_i2c_read_block_data; + ts->ops.ext = ttsp_i2c_tch_ext; + ts->ops.dev = &client->dev; + ts->ops.dev->bus = &i2c_bus_type; + + ts->ttsp_client = cyttsp_core_init(&ts->ops, &client->dev); + if (IS_ERR(ts->ttsp_client)) { + int retval = PTR_ERR(ts->ttsp_client); + kfree(ts); + return retval; + } + + dev_dbg(ts->ops.dev, "%s: Registration complete\n", __func__); + + return 0; +} + + +/* registered in driver struct */ +static int __devexit cyttsp_i2c_remove(struct i2c_client *client) +{ + struct cyttsp_i2c *ts; + + ts = i2c_get_clientdata(client); + cyttsp_core_release(ts->ttsp_client); + kfree(ts); + return 0; +} + +#ifdef CONFIG_PM +static int cyttsp_i2c_suspend(struct i2c_client *client, pm_message_t message) +{ + struct cyttsp_i2c *ts = i2c_get_clientdata(client); + + return cyttsp_suspend(ts->ttsp_client); +} + +static int cyttsp_i2c_resume(struct i2c_client *client) +{ + struct cyttsp_i2c *ts = i2c_get_clientdata(client); + + return cyttsp_resume(ts->ttsp_client); +} +#endif + +static const struct i2c_device_id cyttsp_i2c_id[] = { + { CY_I2C_NAME, 0 }, { } +}; + +static struct i2c_driver cyttsp_i2c_driver = { + .driver = { + .name = CY_I2C_NAME, + .owner = THIS_MODULE, + }, + .probe = cyttsp_i2c_probe, + .remove = __devexit_p(cyttsp_i2c_remove), + .id_table = cyttsp_i2c_id, +#ifdef CONFIG_PM + .suspend = cyttsp_i2c_suspend, + .resume = cyttsp_i2c_resume, +#endif +}; + +static int __init cyttsp_i2c_init(void) +{ + return i2c_add_driver(&cyttsp_i2c_driver); +} + +static void __exit cyttsp_i2c_exit(void) +{ + return i2c_del_driver(&cyttsp_i2c_driver); +} + +module_init(cyttsp_i2c_init); +module_exit(cyttsp_i2c_exit); + +MODULE_ALIAS("i2c:cyttsp"); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard Product (TTSP) I2C driver"); +MODULE_AUTHOR("Cypress"); +MODULE_DEVICE_TABLE(i2c, cyttsp_i2c_id);