From patchwork Mon Sep 7 05:38:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joonyoung Shim X-Patchwork-Id: 46062 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n875xX9w029932 for ; Mon, 7 Sep 2009 05:59:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758856AbZIGF73 (ORCPT ); Mon, 7 Sep 2009 01:59:29 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758859AbZIGF73 (ORCPT ); Mon, 7 Sep 2009 01:59:29 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:35798 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758856AbZIGF71 (ORCPT ); Mon, 7 Sep 2009 01:59:27 -0400 X-Greylist: delayed 705 seconds by postgrey-1.27 at vger.kernel.org; Mon, 07 Sep 2009 01:59:27 EDT Received: from epmmp1 (mailout1.samsung.com [203.254.224.24]) by mailout1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTP id <0KPL00L0R6C3AF@mailout1.samsung.com> for linux-input@vger.kernel.org; Mon, 07 Sep 2009 14:38:27 +0900 (KST) Received: from TNRNDGASPAPP1.tn.corp.samsungelectronics.net ([165.213.149.150]) by mmp1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0KPL004AY6C30H@mmp1.samsung.com> for linux-input@vger.kernel.org; Mon, 07 Sep 2009 14:38:27 +0900 (KST) Received: from [10.89.8.132] ([10.89.8.132]) by TNRNDGASPAPP1.tn.corp.samsungelectronics.net with Microsoft SMTPSVC(6.0.3790.3959); Mon, 07 Sep 2009 14:38:27 +0900 Date: Mon, 07 Sep 2009 14:38:27 +0900 From: Joonyoung Shim Subject: Re: [PATCH 03/03] [INPUT][KEYBOARD] Add new keypad driver for s3c series SoCs In-reply-to: <00b101ca2e30$84135d90$8c3a18b0$%yang@samsung.com> To: =?UTF-8?B?7JaR7KeE7ISx?= Cc: linux-input@vger.kernel.org, laforge@gnumonks.org, ben-linux@fluff.org, =?UTF-8?B?Iuq5gOqyveydvC9BUOqwnOuwnO2MgChTWVMuTFNJKQ==?= =?UTF-8?B?L0UzKOyCrOybkCkv7IK87ISx7KCE7J6QIg==?= , =?UTF-8?B?IifquYDqta3sp4QvQVDqsJzrsJztjIAoU1lT?= =?UTF-8?B?LkxTSSkvRTUo7LGF7J6EKS/sgrzshLHsoITsnpAnIg==?= , dmitry.torokhov@gmail.com, kyungmin.park@samsung.com, jh80.chung@samsung.com Message-id: <4AA49C53.3030400@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 8BIT User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) References: <00b101ca2e30$84135d90$8c3a18b0$%yang@samsung.com> X-OriginalArrivalTime: 07 Sep 2009 05:38:27.0130 (UTC) FILETIME=[6C8121A0:01CA2F7D] Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org On 9/5/2009 10:55 PM, 양진성 wrote: > This keypad driver supports Samsung s3c based SoCs such as s3c6410. > This driver is written with input device compatibles. > > Signed-off-by: Jinsung Yang > Signed-off-by: Kyeongil Kim > --- > drivers/input/keyboard/s3c-keypad.c | 468 +++++++++++++++++++++++++++++++++++ > 1 files changed, 468 insertions(+), 0 deletions(-) > create mode 100644 drivers/input/keyboard/s3c-keypad.c Hi, We already implemented and tested the keypad driver for s5pc100 & s5pc110 and maybe it will operate on s3c64xx. We use the samsung prefix to support three cpu. Because there is no the arch for s5pc100 and s5pc110, this driver doesn't compile yet on upstream kernel. From 0582cd271637aaebed29f2982f941bcf80d84179 Mon Sep 17 00:00:00 2001 From: Joonyoung Shim Date: Mon, 7 Sep 2009 14:35:12 +0900 Subject: [PATCH] Input: add samsung keypad driver for S3C64XX and S5PC1XX cpu This patch adds support for keypad driver running on Samsung S3C64XX and S5PC1XX cpu. Signed-off-by: Joonyoung Shim --- drivers/input/keyboard/Kconfig | 9 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/samsung-keypad.c | 366 +++++++++++++++++++++++++++++++ 3 files changed, 376 insertions(+), 0 deletions(-) create mode 100644 drivers/input/keyboard/samsung-keypad.c diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 3525c19..b2cec96 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -278,6 +278,15 @@ config KEYBOARD_PXA930_ROTARY To compile this driver as a module, choose M here: the module will be called pxa930_rotary. +config KEYBOARD_SAMSUNG + tristate "Samsung keypad support" + depends on ARCH_S3C64XX || ARCH_S5PC1XX + help + Say Y here if you want to use the Samsung keypad. + + To compile this driver as a module, choose M here: the + module will be called samsung-keypad. + config KEYBOARD_SPITZ tristate "Spitz keyboard" depends on PXA_SHARPSL diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 8a7a22b..2fa54a7 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -25,6 +25,7 @@ obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o obj-$(CONFIG_KEYBOARD_PXA930_ROTARY) += pxa930_rotary.o +obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o diff --git a/drivers/input/keyboard/samsung-keypad.c b/drivers/input/keyboard/samsung-keypad.c new file mode 100644 index 0000000..ad025f7 --- /dev/null +++ b/drivers/input/keyboard/samsung-keypad.c @@ -0,0 +1,366 @@ +/* + * samsung-keypad.c -- Samsung keypad driver + * + * Copyright (C) 2009 Samsung Electronics Co.Ltd + * Author: Joonyoung Shim + * Author: Jaehoon Chung + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct samsung_keypad { + struct input_dev *input_dev; + struct clk *clk; + struct delayed_work work; + void __iomem *base; + unsigned short *keycodes; + unsigned int num_cols; + unsigned int last_rows_state; + unsigned int last_cols_val[SAMSUNG_MAX_ROWS]; + int irq; + atomic_t irq_disable; +}; + +static void samsung_kp_scan(struct work_struct *work) +{ + struct samsung_keypad *keypad = container_of(work, + struct samsung_keypad, work.work); + unsigned int row, col, val; + unsigned int mask; + unsigned int released = 0; + + val = readl(keypad->base + SAMSUNG_KEYIFSTSCLR); + + if (cpu_is_s5pc110()) + mask = S5PC110_R_INT_MASK; + else + mask = SAMSUNG_R_INT_MASK; + + if (val & mask) + released = 1; + + if (released) { + if (cpu_is_s5pc110()) { + val &= ~S5PC110_P_INT_MASK; + val = val >> S5PC110_R_INT_OFFSET; + } else { + val &= ~SAMSUNG_P_INT_MASK; + val = val >> SAMSUNG_R_INT_OFFSET; + } + + if (!(keypad->last_rows_state & val)) + goto end; + + row = 0; + while (!(val & 1)) { + val = val >> 1; + row++; + } + + col = keypad->last_cols_val[row]; + keypad->last_rows_state &= ~(1 << row); + dev_dbg(&keypad->input_dev->dev, + "key released, row: %d, col: %d\n", row, col); + } else { + row = 0; + while (!(val & 1)) { + val = val >> 1; + row++; + } + + for (col = 0; col < keypad->num_cols; col++) { + val = readl(keypad->base + SAMSUNG_KEYIFCOL); + val |= SAMSUNG_KEYIFCOL_MASK; + val &= ~(1 << col); + writel(val, keypad->base + SAMSUNG_KEYIFCOL); + + val = readl(keypad->base + SAMSUNG_KEYIFROW); + if (!(val & (1 << row))) { + keypad->last_rows_state |= (1 << row); + keypad->last_cols_val[row] = col; + dev_dbg(&keypad->input_dev->dev, + "key pressed, row: %d, col: %d\n", + row, col); + goto found; + } + } + goto end; + } + +found: + val = (row << keypad->num_cols) + col; + input_report_key(keypad->input_dev, keypad->keycodes[val], !released); + input_sync(keypad->input_dev); + +end: + /* KEYIFCOL reg clear */ + if (cpu_is_s5pc110()) { + val = ~(SAMSUNG_KEYIFCOL_MASK | S5PC110_KEYIFCOLEN_MASK); + writel(val, keypad->base + SAMSUNG_KEYIFCOL); + } else { + val = ~SAMSUNG_KEYIFCOL_MASK; + writel(val, keypad->base + SAMSUNG_KEYIFCOL); + } + + /* interrupt clear */ + if (cpu_is_s5pc110()) + val = S5PC110_P_INT_MASK | S5PC110_R_INT_MASK; + else + val = SAMSUNG_P_INT_MASK | SAMSUNG_R_INT_MASK; + writel(val, keypad->base + SAMSUNG_KEYIFSTSCLR); + + atomic_dec(&keypad->irq_disable); + enable_irq(keypad->irq); +} + +static irqreturn_t samsung_kp_interrupt(int irq, void *dev_id) +{ + struct samsung_keypad *keypad = dev_id; + + if (!work_pending(&keypad->work.work)) { + disable_irq_nosync(keypad->irq); + atomic_inc(&keypad->irq_disable); + schedule_delayed_work(&keypad->work, msecs_to_jiffies(10)); + } + + return IRQ_HANDLED; +} + +static int __devinit samsung_kp_probe(struct platform_device *pdev) +{ + const struct samsung_keypad_platdata *pdata; + struct samsung_keypad *keypad; + struct resource *res; + struct input_dev *input_dev; + unsigned short *keycodes; + unsigned int max_keymap_size; + unsigned int val; + int i; + int ret; + + pdata = pdev->dev.platform_data; + if (!pdata) { + dev_err(&pdev->dev, "no platform data defined\n"); + return -EINVAL; + } + + if ((pdata->num_rows <= 0) || (pdata->num_rows > SAMSUNG_MAX_ROWS)) + return -EINVAL; + + if ((pdata->num_cols <= 0) || (pdata->num_cols > SAMSUNG_MAX_COLS)) + return -EINVAL; + + /* initialize the gpio */ + if (pdata->cfg_gpio) + pdata->cfg_gpio(pdata->num_rows, pdata->num_cols); + + max_keymap_size = pdata->num_rows * pdata->num_cols; + keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); + keycodes = devm_kzalloc(&pdev->dev, + max_keymap_size * sizeof(*keycodes), GFP_KERNEL); + input_dev = input_allocate_device(); + if (!keypad || !keycodes || !input_dev) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + ret = -ENODEV; + goto err_free_mem; + } + + keypad->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); + if (!keypad->base) { + ret = -EBUSY; + goto err_free_mem; + } + + if (pdata->clock) { + keypad->clk = clk_get(&pdev->dev, pdata->clock); + if (IS_ERR(keypad->clk)) { + dev_err(&pdev->dev, "failed to get keypad clk\n"); + ret = PTR_ERR(keypad->clk); + goto err_unmap_base; + } + clk_enable(keypad->clk); + } + + keypad->input_dev = input_dev; + keypad->keycodes = keycodes; + keypad->num_cols = pdata->num_cols; + INIT_DELAYED_WORK(&keypad->work, samsung_kp_scan); + + /* enable interrupt and debouncing filter and wakeup bit */ + val = SAMSUNG_INT_F_EN | SAMSUNG_INT_R_EN | SAMSUNG_DF_EN | + SAMSUNG_WAKEUPEN; + writel(val, keypad->base + SAMSUNG_KEYIFCON); + + keypad->irq = platform_get_irq(pdev, 0); + if (keypad->irq < 0) { + ret = keypad->irq; + goto err_disable_clk; + } + + ret = devm_request_irq(&pdev->dev, keypad->irq, + samsung_kp_interrupt, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + dev_name(&pdev->dev), keypad); + + if (ret) + goto err_disable_clk; + + input_dev->name = pdev->name; + input_dev->id.bustype = BUS_HOST; + input_dev->dev.parent = &pdev->dev; + input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); + + input_dev->keycode = keycodes; + input_dev->keycodesize = sizeof(*keycodes); + input_dev->keycodemax = max_keymap_size; + + for (i = 0; i < pdata->keymap_size; i++) { + unsigned int key = pdata->keymap[i]; + unsigned int row = KEY_ROW(key); + unsigned int col = KEY_COL(key); + unsigned short code = KEY_VAL(key); + unsigned int index = row * keypad->num_cols + col; + + keycodes[index] = code; + set_bit(code, input_dev->keybit); + } + + ret = input_register_device(keypad->input_dev); + if (ret) + goto err_free_irq; + + device_init_wakeup(&pdev->dev, 1); + + platform_set_drvdata(pdev, keypad); + + return 0; + +err_free_irq: + devm_free_irq(&pdev->dev, keypad->irq, keypad); +err_disable_clk: + if (keypad->clk) { + clk_disable(keypad->clk); + clk_put(keypad->clk); + } +err_unmap_base: + devm_iounmap(&pdev->dev, keypad->base); +err_free_mem: + input_free_device(input_dev); + devm_kfree(&pdev->dev, keycodes); + devm_kfree(&pdev->dev, keypad); + + return ret; +} + +static int __devexit samsung_kp_remove(struct platform_device *pdev) +{ + struct samsung_keypad *keypad = platform_get_drvdata(pdev); + + devm_free_irq(&pdev->dev, keypad->irq, keypad); + cancel_delayed_work_sync(&keypad->work); + + /* + * If work indeed has been cancelled, disable_irq() will have been left + * unbalanced from samsung_kp_interrupt(). + */ + while (atomic_dec_return(&keypad->irq_disable) >= 0) + enable_irq(keypad->irq); + + platform_set_drvdata(pdev, NULL); + input_unregister_device(keypad->input_dev); + + if (keypad->clk) { + clk_disable(keypad->clk); + clk_put(keypad->clk); + } + + devm_iounmap(&pdev->dev, keypad->base); + devm_kfree(&pdev->dev, keypad->keycodes); + devm_kfree(&pdev->dev, keypad); + + return 0; +} + +#ifdef CONFIG_PM +static int samsung_kp_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct samsung_keypad *keypad = platform_get_drvdata(pdev); + + disable_irq(keypad->irq); + enable_irq_wake(keypad->irq); + + if (keypad->clk) + clk_disable(keypad->clk); + + return 0; +} + +static int samsung_kp_resume(struct platform_device *pdev) +{ + struct samsung_keypad *keypad = platform_get_drvdata(pdev); + unsigned int val; + + if (keypad->clk) + clk_enable(keypad->clk); + + /* enable interrupt and debouncing filter and wakeup bit */ + val = SAMSUNG_INT_F_EN | SAMSUNG_INT_R_EN | SAMSUNG_DF_EN | + SAMSUNG_WAKEUPEN; + writel(val, keypad->base + SAMSUNG_KEYIFCON); + + disable_irq_wake(keypad->irq); + enable_irq(keypad->irq); + + return 0; +} +#else +#define samsung_kp_suspend NULL +#define samsung_kp_resume NULL +#endif + +static struct platform_driver samsung_kp_driver = { + .probe = samsung_kp_probe, + .remove = __devexit_p(samsung_kp_remove), + .suspend = samsung_kp_suspend, + .resume = samsung_kp_resume, + .driver = { + .name = "samsung-keypad", + .owner = THIS_MODULE, + }, +}; + +static int __init samsung_kp_init(void) +{ + return platform_driver_register(&samsung_kp_driver); +} + +static void __exit samsung_kp_exit(void) +{ + platform_driver_unregister(&samsung_kp_driver); +} + +module_init(samsung_kp_init); +module_exit(samsung_kp_exit); + +MODULE_DESCRIPTION("Samsung keypad driver"); +MODULE_AUTHOR("Joonyoung Shim "); +MODULE_AUTHOR("Jaehoon Chung "); +MODULE_LICENSE("GPL");