Re: [PATCH 03/03] [INPUT][KEYBOARD] Add new keypad driver for s3c series SoCs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <jsgood.yang@xxxxxxxxxxx>
> Signed-off-by: Kyeongil Kim <ki0351.kim@xxxxxxxxxxx>
> ---
>  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 <jy0922.shim@xxxxxxxxxxx>
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 <jy0922.shim@xxxxxxxxxxx>
---
 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 <jy0922.shim@xxxxxxxxxxx>
+ * Author: Jaehoon Chung <jh80.chung@xxxxxxxxxxx>
+ *
+ *  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 <linux/clk.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <mach/cpu.h>
+#include <plat/keypad.h>
+#include <plat/regs-keypad.h>
+
+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 <jy0922.shim@xxxxxxxxxxx>");
+MODULE_AUTHOR("Jaehoon Chung <jh80.chung@xxxxxxxxxxx>");
+MODULE_LICENSE("GPL");
-- 
1.6.0.4
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux