From patchwork Wed Sep 5 11:36:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Poddar, Sourav" X-Patchwork-Id: 1408831 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 1EFD940220 for ; Wed, 5 Sep 2012 11:40:45 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T9Dux-0005bb-Ha; Wed, 05 Sep 2012 11:37:11 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T9Due-0005Rk-7Z for linux-arm-kernel@lists.infradead.org; Wed, 05 Sep 2012 11:36:53 +0000 Received: from dbdp20.itg.ti.com ([172.24.170.38]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id q85BamEt012224; Wed, 5 Sep 2012 06:36:49 -0500 Received: from DBDE71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id q85Bam4P013521; Wed, 5 Sep 2012 17:06:48 +0530 (IST) Received: from dbdp32.itg.ti.com (172.24.170.251) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 14.1.323.3; Wed, 5 Sep 2012 17:06:48 +0530 Received: from a0131647.apr.dhcp.ti.com (smtpvbd.itg.ti.com [172.24.170.250]) by dbdp32.itg.ti.com (8.13.8/8.13.8) with ESMTP id q85Balbr021526; Wed, 5 Sep 2012 17:06:47 +0530 From: Sourav Poddar To: , , , , , Subject: [PATCHv2 2/4] Input: keypad: Add smsc ece1099 keypad driver Date: Wed, 5 Sep 2012 17:06:37 +0530 Message-ID: <1346844997-24868-1-git-send-email-sourav.poddar@ti.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.153 listed in list.dnswl.org] -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: dmitry.torokhov@gmail.com, santosh.shilimkar@ti.com, b-cousson@ti.com, balbi@ti.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: G, Manjunath Kondaiah SMSC ECE1099 is a keyboard scan or GPIO expansion device.The device supports a keypad scan matrix of 23*8.This driver uses this device as a keypad driver. Cc: Dmitry Torokhov Cc: Benoit Cousson Cc: Felipe Balbi Cc: Santosh Shilimkar Signed-off-by: G, Manjunath Kondaiah Signed-off-by: Sourav Poddar Acked-by: Felipe Balbi --- Changes since v1: - Prevent the use of kfree since devm_kzalloc was used. - Use devexit around remove api drivers/input/keyboard/Kconfig | 11 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/smsc-ece1099-keypad.c | 306 ++++++++++++++++++++++++++ 3 files changed, 318 insertions(+), 0 deletions(-) create mode 100644 drivers/input/keyboard/smsc-ece1099-keypad.c diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index c50fa75..2a2d374 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -593,6 +593,17 @@ config KEYBOARD_TWL4030 To compile this driver as a module, choose M here: the module will be called twl4030_keypad. +config KEYBOARD_SMSC + tristate "SMSC ECE1099 keypad support" + depends on I2C=y + help + Say Y here if your board use the smsc keypad controller + for omap5 defconfig. It's safe to say enable this + even on boards that don't use the keypad controller. + + To compile this driver as a module, choose M here: the + module will be called smsc-ece1099-keypad. + config KEYBOARD_XTKBD tristate "XT keyboard" select SERIO diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 44e7600..0f2aa26 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -52,5 +52,6 @@ obj-$(CONFIG_KEYBOARD_TC3589X) += tc3589x-keypad.o obj-$(CONFIG_KEYBOARD_TEGRA) += tegra-kbc.o obj-$(CONFIG_KEYBOARD_TNETV107X) += tnetv107x-keypad.o obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o +obj-$(CONFIG_KEYBOARD_SMSC) += smsc-ece1099-keypad.o obj-$(CONFIG_KEYBOARD_XTKBD) += xtkbd.o obj-$(CONFIG_KEYBOARD_W90P910) += w90p910_keypad.o diff --git a/drivers/input/keyboard/smsc-ece1099-keypad.c b/drivers/input/keyboard/smsc-ece1099-keypad.c new file mode 100644 index 0000000..71cd7d6 --- /dev/null +++ b/drivers/input/keyboard/smsc-ece1099-keypad.c @@ -0,0 +1,306 @@ +/* + * SMSC_ECE1099 Keypad driver + * + * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define KEYPRESS_TIME 200 + +struct smsc_keypad { + struct smsc *smsc; + struct matrix_keymap_data *keymap_data; + unsigned int last_key_state[16]; + unsigned int last_col; + unsigned int last_key_ms[16]; + unsigned short *keymap; + struct i2c_client *client; + struct input_dev *input; + int rows, cols; + int row_shift; + bool no_autorepeat; + unsigned irq; + struct device *dev; +}; + +static void smsc_kp_scan(struct smsc_keypad *kp) +{ + struct input_dev *input = kp->input; + int i, j; + int row, col; + int temp, code; + unsigned int new_state[16]; + unsigned int bits_changed; + int this_ms; + + smsc_write(kp->dev, SMSC_KP_INT_MASK, 0x00); + smsc_write(kp->dev, SMSC_KP_INT_STAT, 0xFF); + + /* Scan for row and column */ + for (i = 0; i < kp->cols; i++) { + smsc_write(kp->dev, SMSC_KP_OUT, SMSC_KSO_EVAL + i); + /* Read Row Status */ + smsc_read(kp->dev, SMSC_KP_IN, &temp); + if (temp == 0xFF) + continue; + + col = i; + for (j = 0; j < kp->rows; j++) { + if ((temp & 0x01) != 0x00) { + temp = temp >> 1; + continue; + } + + row = j; + new_state[col] = (1 << row); + bits_changed = kp->last_key_state[col] ^ new_state[col]; + this_ms = jiffies_to_msecs(jiffies); + if (bits_changed != 0 || (!bits_changed && + ((this_ms - kp->last_key_ms[col]) >= KEYPRESS_TIME))) { + code = MATRIX_SCAN_CODE(row, col, kp->row_shift); + input_event(input, EV_MSC, MSC_SCAN, code); + input_report_key(input, kp->keymap[code], 1); + input_report_key(input, kp->keymap[code], 0); + kp->last_key_state[col] = new_state[col]; + if (kp->last_col != col) + kp->last_key_state[kp->last_col] = 0; + kp->last_key_ms[col] = this_ms; + } + temp = temp >> 1; + } + } + input_sync(input); + + smsc_write(kp->dev, SMSC_KP_INT_MASK, 0xFF); + + /* Set up Low Power Mode (Wake-up) (0xFB) */ + smsc_write(kp->dev, SMSC_WKUP_CTRL, SMSC_KP_SET_LOW_PWR); + + /*Enable Keypad Scan (generate interrupt on key press) (0x40)*/ + smsc_write(kp->dev, SMSC_KP_OUT, SMSC_KSO_ALL_LOW); +} + +static irqreturn_t do_kp_irq(int irq, void *_kp) +{ + struct smsc_keypad *kp = _kp; + int int_status; + + smsc_read(kp->dev, SMSC_KP_INT_STAT, &int_status); + if (int_status) + smsc_kp_scan(kp); + + return IRQ_HANDLED; +} + +#ifdef CONFIG_OF +static int __devinit smsc_keypad_parse_dt(struct device *dev, + struct smsc_keypad *kp) +{ + struct device_node *np = dev->of_node; + + if (!np) { + dev_err(dev, "missing DT data"); + return -EINVAL; + } + + of_property_read_u32(np, "keypad,num-rows", &kp->rows); + of_property_read_u32(np, "keypad,num-columns", &kp->cols); + if (!kp->rows || !kp->cols) { + dev_err(dev, "number of keypad rows/columns not specified\n"); + return -EINVAL; + } + + if (of_get_property(np, "linux,input-no-autorepeat", NULL)) + kp->no_autorepeat = true; + + return 0; +} +#else +static inline int smsc_keypad_parse_dt(struct device *dev, + struct smsc_keypad *kp) +{ + return -ENOSYS; +} +#endif + +static int __devinit +smsc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct smsc *smsc = dev_get_drvdata(pdev->dev.parent); + struct input_dev *input; + struct smsc_keypad *kp; + int ret = 0, error; + int col, i, max_keys, row_shift; + int irq; + int addr_start, addr; + + kp = devm_kzalloc(dev, sizeof(*kp), GFP_KERNEL); + + input = input_allocate_device(); + if (!kp || !input) { + error = -ENOMEM; + goto err1; + } + + error = smsc_keypad_parse_dt(&pdev->dev, kp); + if (error) + return error; + + /* Get the debug Device */ + kp->input = input; + kp->smsc = smsc; + kp->irq = platform_get_irq(pdev, 0); + kp->dev = dev; + + for (col = 0; col < 16; col++) { + kp->last_key_state[col] = 0; + kp->last_key_ms[col] = 0; + } + + /* setup input device */ + __set_bit(EV_KEY, input->evbit); + + /* Enable auto repeat feature of Linux input subsystem */ + if (!(kp->no_autorepeat)) + __set_bit(EV_REP, input->evbit); + + input_set_capability(input, EV_MSC, MSC_SCAN); + input->name = "SMSC Keypad"; + input->phys = "smsc_keypad/input0"; + input->dev.parent = &pdev->dev; + input->id.bustype = BUS_HOST; + input->id.vendor = 0x0001; + input->id.product = 0x0001; + input->id.version = 0x0003; + + error = input_register_device(input); + if (error) { + dev_err(kp->dev, + "Unable to register twl4030 keypad device\n"); + goto err1; + } + + /* Mask all GPIO interrupts (0x37-0x3B) */ + for (addr = 0x37; addr < 0x3B; addr++) + smsc_write(dev, addr, 0); + + /* Set all outputs high (0x05-0x09) */ + for (addr = 0x05; addr < 0x09; addr++) + smsc_write(dev, addr, 0xff); + + /* Clear all GPIO interrupts (0x32-0x36) */ + for (addr = 0x32; addr < 0x36; addr++) + smsc_write(dev, addr, 0xff); + + addr_start = 0x12; + for (i = 0; i <= kp->rows; i++) { + addr = 0x12 + i; + smsc_write(dev, addr, SMSC_KP_KSI); + } + + addr_start = 0x1A; + for (i = 0; i <= kp->cols; i++) { + addr = 0x1A + i; + smsc_write(dev, addr, SMSC_KP_KSO); + } + + addr = SMSC_KP_INT_STAT; + smsc_write(dev, addr, SMSC_KP_SET_HIGH); + + addr = SMSC_WKUP_CTRL; + smsc_write(dev, addr, SMSC_KP_SET_LOW_PWR); + + addr = SMSC_KP_OUT; + smsc_write(dev, addr, SMSC_KSO_ALL_LOW); + + row_shift = get_count_order(kp->cols); + max_keys = kp->rows << row_shift; + + kp->row_shift = row_shift; + kp->keymap = kzalloc(max_keys * sizeof(kp->keymap[0]), + GFP_KERNEL); + if (!kp->keymap) { + dev_err(&pdev->dev, "Not enough memory for keymap\n"); + error = -ENOMEM; + } + + matrix_keypad_build_keymap(NULL, NULL, kp->rows, + kp->cols, kp->keymap, input); + + /* + * This ISR will always execute in kernel thread context because of + * the need to access the SMSC over the I2C bus. + */ + ret = devm_request_threaded_irq(dev, kp->irq, NULL, do_kp_irq, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, pdev->name, kp); + if (ret) { + dev_dbg(&pdev->dev, "request_irq failed for irq no=%d\n", + irq); + goto err2; + } + + /* Enable smsc keypad interrupts */ + ret = smsc_write(dev, SMSC_KP_INT_MASK, 0xff); + if (ret < 0) + goto err2; + + return 0; + +err2: + input_unregister_device(input); +err1: + input_free_device(input); + return ret; +} + +static int __devexit smsc_remove(struct platform_device *pdev) +{ + struct smsc_keypad *kp = platform_get_drvdata(pdev); + input_unregister_device(kp->input); + + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id smsc_keypad_dt_match[] = { + { .compatible = "smsc,keypad" }, + {}, +}; +MODULE_DEVICE_TABLE(of, smsc_keypad_dt_match); +#endif + +static struct platform_driver smsc_driver = { + .driver = { + .name = "smsc-keypad", + .of_match_table = of_match_ptr(smsc_keypad_dt_match), + .owner = THIS_MODULE, + }, + .probe = smsc_probe, + .remove = __devexit_p(smsc_remove), +}; + +module_platform_driver(smsc_driver); + +MODULE_AUTHOR("G Kondaiah Manjunath "); +MODULE_DESCRIPTION("SMSC ECE1099 Keypad driver"); +MODULE_LICENSE("GPL v2");