From patchwork Fri Sep 3 20:37:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 154881 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 o83Kbhh6025231 for ; Fri, 3 Sep 2010 20:37:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754705Ab0ICUhY (ORCPT ); Fri, 3 Sep 2010 16:37:24 -0400 Received: from mail-pw0-f46.google.com ([209.85.160.46]:47986 "EHLO mail-pw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754039Ab0ICUhX (ORCPT ); Fri, 3 Sep 2010 16:37:23 -0400 Received: by pwi3 with SMTP id 3so347875pwi.19 for ; Fri, 03 Sep 2010 13:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=zHoFcMUMPmzBPg57klreWl3d8K2J8UOMYxSjXIVddh0=; b=Ab+2aK8KBTelskWx7v3Vofu8wjXVNH3ObkDAAlTyJOv5RYnsIL4yYqSUmy7NbT8oyU mU3JBVvq+xUFivjr/cfDHkpM7X20E/ug4MaMZSYSi7hYu5lp86n0qUuT5dQU5cSD/fvv HibC4pOOZT7bwRBhS7yT7WS/LGhw8Oukch2wE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=Od59xfYoXwVtHVKiSWo+yh0kZcG202oZ6hxkSVoZddRkVdvfr/suw5CAM4A8KzA4JI gTDS4e023VhMlpTdGhsCNKPPtyzj+91xzkLC3D/hFkqSBmh0Fdd69k9uutbueUjsVPD6 AiqI+dLSt/RnHkWHjRrR3WRMjzwa3CnAf2RiY= Received: by 10.114.77.11 with SMTP id z11mr98277waa.112.1283546242274; Fri, 03 Sep 2010 13:37:22 -0700 (PDT) Received: from mailhub.coreip.homeip.net (c-24-6-153-206.hsd1.ca.comcast.net [24.6.153.206]) by mx.google.com with ESMTPS id d38sm4451514wam.8.2010.09.03.13.37.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 03 Sep 2010 13:37:20 -0700 (PDT) Date: Fri, 3 Sep 2010 13:37:17 -0700 From: Dmitry Torokhov To: Neil Leeder Cc: "linux-input@vger.kernel.org" , "linux-arm-msm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Horace Fu , Hsin.Wu@quantatw.com, mcuos.com@gmail.com Subject: Re: [PATCH 0/1] input: keyboard: add qci keyboard driver Message-ID: <20100903203717.GA6412@core.coreip.homeip.net> References: <4C7838DD.1020004@codeaurora.org> <201008271533.01542.dmitry.torokhov@gmail.com> <4C7BF6D2.5080501@codeaurora.org> <20100830215556.GC28865@core.coreip.homeip.net> <4C7D6C17.1070604@codeaurora.org> <20100901063430.GG23585@core.coreip.homeip.net> <4C8148C6.2010006@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4C8148C6.2010006@codeaurora.org> User-Agent: Mutt/1.5.20 (2009-12-10) 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]); Fri, 03 Sep 2010 20:38:16 +0000 (UTC) diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index d63f566..2f38feb 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -373,6 +373,18 @@ config KEYBOARD_SAMSUNG To compile this driver as a module, choose M here: the module will be called samsung-keypad. +config KEYBOARD_QCIGKBD + tristate "Quanta Computer Inc. keyboard" + depends on I2C + help + This driver supports the i2c keyboard on Quanta smartbook devices. + + Say Y here if you have a Quanta-based smartbook or notepad + device and want to use the Quanta i2c keyboard driver. + + To compile this driver as a module, choose M here: the + module will be called qci_gkbd. + config KEYBOARD_STOWAWAY tristate "Stowaway keyboard" select SERIO diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index c13809c..82f69f7 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_KEYBOARD_OMAP4) += omap4-keypad.o obj-$(CONFIG_KEYBOARD_OPENCORES) += opencores-kbd.o obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o +obj-$(CONFIG_KEYBOARD_QCIGKBD) += qci_gkbd.o obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o diff --git a/drivers/input/keyboard/qci_gkbd.c b/drivers/input/keyboard/qci_gkbd.c new file mode 100644 index 0000000..6cc06c4 --- /dev/null +++ b/drivers/input/keyboard/qci_gkbd.c @@ -0,0 +1,259 @@ +/* Quanta I2C Keyboard Driver + * + * Copyright (C) 2009 Quanta Computer Inc. + * 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. + * + */ + +/* + * This driver communicates via I2C to the nuvoTon WPCE775x Embedded + * Controller, which has the keyboard attached to it. + * + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define QCI_KEYBOARD_ID_NAME "qci-gkbd" +#define QCI_KEYBOARD_NAME "Quanta Keyboard" +#define QCI_KEYBOARD_DEVICE "/qci-gkbd/input0" +#define QCI_KEYBOARD_CMD_ENABLE 0xF4 +#define QCI_KEYBOARD_CMD_DISABLE 0xF5 +#define QCI_KEYBOARD_ACK 0xFA +#define QCI_KEYBOARD_MAX_KEY 127 + +struct qci_keyboard { + struct i2c_client *client; + struct input_dev *input; + unsigned int gpio; + unsigned int irq; +}; + +#ifdef CONFIG_PM +static int qcikbd_suspend(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct qci_keyboard *qcikbd = i2c_get_clientdata(client); + + disable_irq(qcikbd->irq); + + return 0; +} + +static int qcikbd_resume(struct device *dev) +{ + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct qci_keyboard *qcikbd = i2c_get_clientdata(client); + + enable_irq(qcikbd->irq); + + return 0; +} + +static const struct dev_pm_ops qcikbd_pm_ops = { + .suspend = qcikbd_suspend, + .resume = qcikbd_resume, +}; +#endif + +static irqreturn_t qcikbd_interrupt(int irq, void *dev_id) +{ + struct qci_keyboard *qcikbd = dev_id; + struct input_dev *input = qcikbd->input; + int rc; + unsigned int scancode; + unsigned char data; + bool down; + + rc = i2c_master_recv(qcikbd->client, &data, 1); + if (rc != 1) + goto irq_exit; + + if (data == QCI_KEYBOARD_ACK) + goto irq_exit; + + scancode = data & 0x7f; + down = !(data & 0x80); + + if (scancode) { + input_event(input, EV_MSC, MSC_SCAN, scancode); + input_report_key(input, scancode, down); + input_sync(input); + } + +irq_exit: + return IRQ_HANDLED; +} + +static int qcikbd_open(struct input_dev *dev) +{ + struct qci_keyboard *qcikbd = input_get_drvdata(dev); + u8 buf[1] = { QCI_KEYBOARD_CMD_ENABLE }; + + i2c_master_send(qcikbd->client, buf, 1); + + return 0; +} + +static void qcikbd_close(struct input_dev *dev) +{ + struct qci_keyboard *qcikbd = input_get_drvdata(dev); + u8 buf[1] = { QCI_KEYBOARD_CMD_DISABLE }; + + i2c_master_send(qcikbd->client, buf, 1); +} + +static int __devinit qcikbd_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + const struct qci_keyboard_platform_data *pd = client->dev.platform_data; + struct qci_keyboard *qcikbd; + struct input_dev *input; + int irq_trigger_type; + int err; + int i; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + pr_err("i2c functionality failed\n"); + return -ENODEV; + } + + qcikbd = kzalloc(sizeof(struct qci_keyboard), GFP_KERNEL); + input = input_allocate_device(); + if (!qcikbd || input) { + err = -ENOMEM; + goto err_free_mem; + } + + qcikbd->client = client; + qcikbd->input = input; + qcikbd->gpio = client->irq; + + input->name = QCI_KEYBOARD_NAME; + input->phys = QCI_KEYBOARD_DEVICE; + input->id.bustype = BUS_I2C; + input->id.vendor = 0x1050; + input->id.product = 0x0006; + input->id.version = 0x0004; + input->open = qcikbd_open; + input->close = qcikbd_close; + + __set_bit(EV_KEY, input->evbit); + __set_bit(EV_REP, input->evbit); + __set_bit(MSC_SCAN, input->mscbit); + + /* Enable all supported keys */ + for (i = 1; i <= QCI_KEYBOARD_MAX_KEY; i++) + __set_bit(i, input->keybit); + + input_set_drvdata(qcikbd->input, qcikbd); + + err = gpio_request(qcikbd->gpio, "qci-gkbd"); + if (err) { + pr_err("gpio request failed\n"); + goto err_free_mem; + } + + err = gpio_direction_input(qcikbd->gpio); + if (err) { + pr_err("gpio direction failed\n"); + goto err_free_gpio; + } + + qcikbd->irq = gpio_to_irq(qcikbd->gpio); + irq_trigger_type = pd ? pd->irq_trigger_type : IRQF_TRIGGER_FALLING; + err = request_threaded_irq(qcikbd->irq, NULL, qcikbd_interrupt, + irq_trigger_type, client->name, qcikbd); + if (err) { + pr_err("unable to get IRQ\n"); + goto err_free_gpio; + } + + err = input_register_device(qcikbd->input); + if (err) { + pr_err("input register device failed\n"); + goto err_free_irq; + } + + i2c_set_clientdata(client, qcikbd); + return 0; + +err_free_irq: + free_irq(qcikbd->irq, qcikbd); +err_free_gpio: + gpio_free(qcikbd->gpio); +err_free_mem: + input_free_device(input); + kfree(qcikbd); + + return err; +} + +static int __devexit qcikbd_remove(struct i2c_client *dev) +{ + struct qci_keyboard *qcikbd = i2c_get_clientdata(dev); + + free_irq(qcikbd->irq, qcikbd); + gpio_free(qcikbd->gpio); + input_unregister_device(qcikbd->input); + kfree(qcikbd); + + return 0; +} + +static const struct i2c_device_id qcikbd_idtable[] = { + { "wpce775-keyboard", 0 }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, qcikbd_idtable); + +static struct i2c_driver i2ckbd_driver = { + .driver = { + .owner = THIS_MODULE, + .name = QCI_KEYBOARD_ID_NAME, +#ifdef CONFIG_PM + .pm = &qcikbd_pm_ops, +#endif + }, + .probe = qcikbd_probe, + .remove = __devexit_p(qcikbd_remove), + .id_table = qcikbd_idtable, +}; + +static int __init qcikbd_init(void) +{ + return i2c_add_driver(&i2ckbd_driver); +} + +static void __exit qcikbd_exit(void) +{ + i2c_del_driver(&i2ckbd_driver); +} + +module_init(qcikbd_init); +module_exit(qcikbd_exit); + +MODULE_AUTHOR("Quanta Computer Inc."); +MODULE_DESCRIPTION("Quanta Embedded Controller I2C Keyboard Driver"); +MODULE_ALIAS("platform:qci-gkbd"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/input/qci_keyboard.h b/include/linux/input/qci_keyboard.h new file mode 100644 index 0000000..b32b7fc --- /dev/null +++ b/include/linux/input/qci_keyboard.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_KEYBOARD_H +#define __QCI_KEYBOARD_H + +struct qci_keyboard_platform_data { + unsigned long irq_trigger_type; +}; + +#endif