Input: add qci touchpad driver From: Neil Leeder This driver is for the QCI trackpad used on Quanta smartbooks Signed-off-by: Horace Fu Signed-off-by: Mandeep Singh Baines [nleeder@codeaurora.org: cleanup i2c calls, address review comments etc] Signed-off-by: Neil Leeder Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/Kconfig | 12 ++ drivers/input/mouse/Makefile | 1 drivers/input/mouse/qci_touchpad.c | 279 ++++++++++++++++++++++++++++++++++++ include/linux/input/qci_touchpad.h | 25 +++ 4 files changed, 317 insertions(+), 0 deletions(-) create mode 100644 drivers/input/mouse/qci_touchpad.c create mode 100644 include/linux/input/qci_touchpad.h diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig index c714ca2..fec262a 100644 --- a/drivers/input/mouse/Kconfig +++ b/drivers/input/mouse/Kconfig @@ -303,6 +303,18 @@ config MOUSE_MAPLE To compile this driver as a module choose M here: the module will be called maplemouse. +config MOUSE_QCITP + tristate "Quanta Computer Inc. I2C Touchpad" + depends on I2C + help + This driver supports the touchpad on Quanta smartbook devices. + + Say Y here if you have a Quanta-based smartbook or notepad + device and want to use the Quanta i2c touchpad driver. + + To compile this driver as a module, choose M here: the + module will be called qci_touchpad. + config MOUSE_SYNAPTICS_I2C tristate "Synaptics I2C Touchpad support" depends on I2C diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile index 570c84a4..6eda35d 100644 --- a/drivers/input/mouse/Makefile +++ b/drivers/input/mouse/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o obj-$(CONFIG_MOUSE_PC110PAD) += pc110pad.o obj-$(CONFIG_MOUSE_PS2) += psmouse.o obj-$(CONFIG_MOUSE_PXA930_TRKBALL) += pxa930_trkball.o +obj-$(CONFIG_MOUSE_QCITP) += qci_touchpad.o obj-$(CONFIG_MOUSE_RISCPC) += rpcmouse.o obj-$(CONFIG_MOUSE_SERIAL) += sermouse.o obj-$(CONFIG_MOUSE_SYNAPTICS_I2C) += synaptics_i2c.o diff --git a/drivers/input/mouse/qci_touchpad.c b/drivers/input/mouse/qci_touchpad.c new file mode 100644 index 0000000..ac52403 --- /dev/null +++ b/drivers/input/mouse/qci_touchpad.c @@ -0,0 +1,279 @@ +/* Quanta I2C Touchpad Driver + * + * Copyright (C) 2009 Quanta Computer Inc. + * Copyright (c) 2010, Code Aurora Forum. All rights reserved. + * Author: Hsin Wu + * Author: Austin Lai + * + * 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. + * + */ + +/* + * Driver communicates over i2c to nuvoTon WPCE775x Embedded Controller, + * which has touchpad attached through PS/2 interface. Unfortunately + * firmware does not seem to fully support PS/2 protocol so attempts to + * turn the driver into serio and use standard psmouse module to drive + * the touchpad failed. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TOUCHPAD_ID_NAME "qci-i2cpad" +#define TOUCHPAD_NAME "QCI Touchpad" +#define TOUCHPAD_DEVICE "/qci_touchpad/input0" +#define TOUCHPAD_CMD_ENABLE 0xF4 +#define TOUCHPAD_CMD_DISABLE 0xF5 +#define TOUCHPAD_READ_DATA_LEN 3 +#define TOUCHPAD_INIT_DELAY_MS 100 + +struct qci_touchpad { + struct i2c_client *client; + struct input_dev *input; + unsigned int gpio; + unsigned int irq; +}; + +#ifdef CONFIG_PM +static int qcitp_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct qci_touchpad *tpad = i2c_get_clientdata(client); + + disable_irq(tpad->irq); + + return 0; +} + +static int qcitp_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct qci_touchpad *tpad = i2c_get_clientdata(client); + + enable_irq(tpad->irq); + + return 0; +} + +static const struct dev_pm_ops qcitp_pm_ops = { + .suspend = qcitp_suspend, + .resume = qcitp_resume, +}; +#endif + +static void qcitp_report_key(struct input_dev *tpad_dev, char *ec_data) +{ + int dx = 0; + int dy = 0; + + if (ec_data[1]) + dx = (int) ec_data[1] - + (int) ((ec_data[0] << 4) & 0x100); + + if (ec_data[2]) + dy = (int) ((ec_data[0] << 3) & 0x100) - + (int) ec_data[2]; + + input_report_key(tpad_dev, BTN_LEFT, ec_data[0] & 0x01); + input_report_key(tpad_dev, BTN_RIGHT, ec_data[0] & 0x02); + input_report_key(tpad_dev, BTN_MIDDLE, ec_data[0] & 0x04); + input_report_rel(tpad_dev, REL_X, dx); + input_report_rel(tpad_dev, REL_Y, dy); + input_sync(tpad_dev); +} + +static irqreturn_t qcitp_interrupt(int irq, void *dev_id) +{ + struct qci_touchpad *tpad = dev_id; + char ecdata[TOUCHPAD_READ_DATA_LEN]; + int rc; + + rc = i2c_master_recv(tpad->client, ecdata, TOUCHPAD_READ_DATA_LEN); + if (rc == TOUCHPAD_READ_DATA_LEN) + qcitp_report_key(tpad->input, ecdata); + + return IRQ_HANDLED; +} + +static int qcitp_open(struct input_dev *input) +{ + struct qci_touchpad *tpad = input_get_drvdata(input); + u8 buf[1] = { TOUCHPAD_CMD_ENABLE }; + int err; + + buf[0] = TOUCHPAD_CMD_ENABLE; + err = i2c_master_send(tpad->client, buf, 1); + if (err < 0) + return err; + + msleep(TOUCHPAD_INIT_DELAY_MS); + + return i2c_master_recv(tpad->client, buf, 1); +} + +static void qcitp_close(struct input_dev *input) +{ + struct qci_touchpad *tpad = input_get_drvdata(input); + u8 buf[1] = { TOUCHPAD_CMD_DISABLE }; + int err; + + err = i2c_master_send(tpad->client, buf, 1); + if (err == 0) { + msleep(TOUCHPAD_INIT_DELAY_MS); + /* read ACK */ + i2c_master_recv(tpad->client, buf, 1); + } +} + + +static int __devinit qcitp_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + const struct qci_touchpad_platform_data *pd = client->dev.platform_data; + struct qci_touchpad *tpad; + struct input_dev *input; + int irq_trigger_type; + int err; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + pr_err("i2c functionality failed\n"); + return -ENODEV; + } + + tpad = kzalloc(sizeof(struct qci_touchpad), GFP_KERNEL); + input = input_allocate_device(); + if (!tpad || !input) { + err = -ENOMEM; + goto err_free_mem; + } + + tpad->client = client; + tpad->input = input; + tpad->gpio = client->irq; + + input->name = TOUCHPAD_NAME; + input->phys = TOUCHPAD_DEVICE; + input->id.bustype = BUS_I2C; + input->id.vendor = 0x1050; + input->id.product = 0x1; + input->id.version = 0x1; + + input->open = qcitp_open; + input->close = qcitp_close; + + input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); + input->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); + input->keybit[BIT_WORD(BTN_LEFT)] = + BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); + + input_set_drvdata(input, tpad); + + err = gpio_request(tpad->gpio, "qci-pad"); + if (err) { + pr_err("gpio request failed\n"); + goto err_free_mem; + } + + err = gpio_direction_input(tpad->gpio); + if (err) { + pr_err("gpio direction input failed\n"); + goto err_free_gpio; + } + + tpad->irq = gpio_to_irq(tpad->gpio); + irq_trigger_type = pd ? pd->irq_trigger_type : IRQF_TRIGGER_FALLING; + + err = request_threaded_irq(tpad->irq, NULL, qcitp_interrupt, + irq_trigger_type, client->name, tpad); + if (err) { + pr_err("request threaded irq failed\n"); + goto err_free_gpio; + } + + err = input_register_device(tpad->input); + if (err) { + pr_err("register device failed\n"); + goto err_free_irq; + } + + i2c_set_clientdata(client, tpad); + return 0; + +err_free_irq: + free_irq(tpad->irq, tpad); +err_free_gpio: + gpio_free(tpad->gpio); +err_free_mem: + input_free_device(input); + kfree(tpad); + return err; +} + +static int __devexit qcitp_remove(struct i2c_client *client) +{ + struct qci_touchpad *tpad = i2c_get_clientdata(client); + + free_irq(tpad->irq, tpad); + gpio_free(tpad->gpio); + input_unregister_device(tpad->input); + kfree(tpad); + + return 0; +} + +static const struct i2c_device_id qcitp_idtable[] = { + { "wpce775-touchpad", 0 }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, qcitp_idtable); + +static struct i2c_driver i2ctp_driver = { + .driver = { + .owner = THIS_MODULE, + .name = TOUCHPAD_ID_NAME, +#ifdef CONFIG_PM + .pm = &qcitp_pm_ops, +#endif + }, + .probe = qcitp_probe, + .remove = __devexit_p(qcitp_remove), + .id_table = qcitp_idtable, +}; + +static int __init qcitp_init(void) +{ + return i2c_add_driver(&i2ctp_driver); +} + + +static void __exit qcitp_exit(void) +{ + i2c_del_driver(&i2ctp_driver); +} + +module_init(qcitp_init); +module_exit(qcitp_exit); + +MODULE_AUTHOR("Quanta Computer Inc."); +MODULE_DESCRIPTION("Quanta Embedded Controller I2C Touchpad Driver"); +MODULE_ALIAS("platform:qci-touchpad"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/input/qci_touchpad.h b/include/linux/input/qci_touchpad.h new file mode 100644 index 0000000..8e266e4 --- /dev/null +++ b/include/linux/input/qci_touchpad.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2010, Code Aurora Forum. All rights reserved. + * + * 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. + */ + +#ifndef __QCI_TOUCHPAD_H +#define __QCI_TOUCHPAD_H + +struct qci_touchpad_platform_data { + unsigned long irq_trigger_type; +}; + +#endif