2009-08-10 12:22:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2009 Nuvoton technology corporation.
|
|
|
|
*
|
|
|
|
* Wan ZongShun <mcuos.com@gmail.com>
|
|
|
|
*
|
|
|
|
* 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;version 2 of the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-08-10 12:22:22 +08:00
|
|
|
|
|
|
|
#include <mach/w90p910_keypad.h>
|
|
|
|
|
|
|
|
/* Keypad Interface Control Registers */
|
|
|
|
#define KPI_CONF 0x00
|
|
|
|
#define KPI_3KCONF 0x04
|
|
|
|
#define KPI_LPCONF 0x08
|
|
|
|
#define KPI_STATUS 0x0C
|
|
|
|
|
|
|
|
#define IS1KEY (0x01 << 16)
|
|
|
|
#define INTTR (0x01 << 21)
|
|
|
|
#define KEY0R (0x0f << 3)
|
|
|
|
#define KEY0C 0x07
|
|
|
|
#define DEBOUNCE_BIT 0x08
|
|
|
|
#define KSIZE0 (0x01 << 16)
|
|
|
|
#define KSIZE1 (0x01 << 17)
|
|
|
|
#define KPSEL (0x01 << 19)
|
|
|
|
#define ENKP (0x01 << 18)
|
|
|
|
|
|
|
|
#define KGET_RAW(n) (((n) & KEY0R) >> 3)
|
|
|
|
#define KGET_COLUMN(n) ((n) & KEY0C)
|
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
#define W90P910_MAX_KEY_NUM (8 * 8)
|
|
|
|
#define W90P910_ROW_SHIFT 3
|
2009-08-10 12:22:22 +08:00
|
|
|
|
|
|
|
struct w90p910_keypad {
|
2009-08-10 12:22:22 +08:00
|
|
|
const struct w90p910_keypad_platform_data *pdata;
|
2009-08-10 12:22:22 +08:00
|
|
|
struct clk *clk;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
void __iomem *mmio_base;
|
|
|
|
int irq;
|
2009-08-10 12:22:22 +08:00
|
|
|
unsigned short keymap[W90P910_MAX_KEY_NUM];
|
2009-08-10 12:22:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void w90p910_keypad_scan_matrix(struct w90p910_keypad *keypad,
|
|
|
|
unsigned int status)
|
|
|
|
{
|
2009-08-10 12:22:22 +08:00
|
|
|
struct input_dev *input_dev = keypad->input_dev;
|
|
|
|
unsigned int row = KGET_RAW(status);
|
|
|
|
unsigned int col = KGET_COLUMN(status);
|
|
|
|
unsigned int code = MATRIX_SCAN_CODE(row, col, W90P910_ROW_SHIFT);
|
|
|
|
unsigned int key = keypad->keymap[code];
|
|
|
|
|
|
|
|
input_event(input_dev, EV_MSC, MSC_SCAN, code);
|
|
|
|
input_report_key(input_dev, key, 1);
|
|
|
|
input_sync(input_dev);
|
|
|
|
|
|
|
|
input_event(input_dev, EV_MSC, MSC_SCAN, code);
|
|
|
|
input_report_key(input_dev, key, 0);
|
|
|
|
input_sync(input_dev);
|
2009-08-10 12:22:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t w90p910_keypad_irq_handler(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct w90p910_keypad *keypad = dev_id;
|
|
|
|
unsigned int kstatus, val;
|
|
|
|
|
|
|
|
kstatus = __raw_readl(keypad->mmio_base + KPI_STATUS);
|
|
|
|
|
|
|
|
val = INTTR | IS1KEY;
|
|
|
|
|
|
|
|
if (kstatus & val)
|
|
|
|
w90p910_keypad_scan_matrix(keypad, kstatus);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int w90p910_keypad_open(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct w90p910_keypad *keypad = input_get_drvdata(dev);
|
2009-08-10 12:22:22 +08:00
|
|
|
const struct w90p910_keypad_platform_data *pdata = keypad->pdata;
|
2009-08-10 12:22:22 +08:00
|
|
|
unsigned int val, config;
|
|
|
|
|
|
|
|
/* Enable unit clock */
|
|
|
|
clk_enable(keypad->clk);
|
|
|
|
|
|
|
|
val = __raw_readl(keypad->mmio_base + KPI_CONF);
|
|
|
|
val |= (KPSEL | ENKP);
|
|
|
|
val &= ~(KSIZE0 | KSIZE1);
|
|
|
|
|
|
|
|
config = pdata->prescale | (pdata->debounce << DEBOUNCE_BIT);
|
|
|
|
|
|
|
|
val |= config;
|
|
|
|
|
|
|
|
__raw_writel(val, keypad->mmio_base + KPI_CONF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void w90p910_keypad_close(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct w90p910_keypad *keypad = input_get_drvdata(dev);
|
|
|
|
|
|
|
|
/* Disable clock unit */
|
|
|
|
clk_disable(keypad->clk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit w90p910_keypad_probe(struct platform_device *pdev)
|
|
|
|
{
|
2009-08-10 12:22:22 +08:00
|
|
|
const struct w90p910_keypad_platform_data *pdata =
|
|
|
|
pdev->dev.platform_data;
|
2009-08-31 02:30:48 +08:00
|
|
|
const struct matrix_keymap_data *keymap_data;
|
2009-08-10 12:22:22 +08:00
|
|
|
struct w90p910_keypad *keypad;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
struct resource *res;
|
2009-08-10 12:22:22 +08:00
|
|
|
int irq;
|
|
|
|
int error;
|
2009-08-10 12:22:22 +08:00
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
if (!pdata) {
|
2009-08-10 12:22:22 +08:00
|
|
|
dev_err(&pdev->dev, "no platform data defined\n");
|
2009-08-10 12:22:22 +08:00
|
|
|
return -EINVAL;
|
2009-08-10 12:22:22 +08:00
|
|
|
}
|
|
|
|
|
2009-08-31 02:30:48 +08:00
|
|
|
keymap_data = pdata->keymap_data;
|
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to get keypad irq\n");
|
2009-08-10 12:22:22 +08:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
keypad = kzalloc(sizeof(struct w90p910_keypad), GFP_KERNEL);
|
|
|
|
input_dev = input_allocate_device();
|
|
|
|
if (!keypad || !input_dev) {
|
|
|
|
dev_err(&pdev->dev, "failed to allocate driver data\n");
|
|
|
|
error = -ENOMEM;
|
2009-08-10 12:22:22 +08:00
|
|
|
goto failed_free;
|
|
|
|
}
|
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
keypad->pdata = pdata;
|
|
|
|
keypad->input_dev = input_dev;
|
|
|
|
keypad->irq = irq;
|
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res == NULL) {
|
|
|
|
dev_err(&pdev->dev, "failed to get I/O memory\n");
|
|
|
|
error = -ENXIO;
|
|
|
|
goto failed_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = request_mem_region(res->start, resource_size(res), pdev->name);
|
|
|
|
if (res == NULL) {
|
|
|
|
dev_err(&pdev->dev, "failed to request I/O memory\n");
|
|
|
|
error = -EBUSY;
|
|
|
|
goto failed_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
keypad->mmio_base = ioremap(res->start, resource_size(res));
|
|
|
|
if (keypad->mmio_base == NULL) {
|
|
|
|
dev_err(&pdev->dev, "failed to remap I/O memory\n");
|
|
|
|
error = -ENXIO;
|
2009-08-10 12:22:22 +08:00
|
|
|
goto failed_free_res;
|
2009-08-10 12:22:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
keypad->clk = clk_get(&pdev->dev, NULL);
|
|
|
|
if (IS_ERR(keypad->clk)) {
|
|
|
|
dev_err(&pdev->dev, "failed to get keypad clock\n");
|
|
|
|
error = PTR_ERR(keypad->clk);
|
|
|
|
goto failed_free_io;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set multi-function pin for w90p910 kpi. */
|
|
|
|
mfp_set_groupi(&pdev->dev);
|
|
|
|
|
|
|
|
input_dev->name = pdev->name;
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
|
|
|
input_dev->open = w90p910_keypad_open;
|
|
|
|
input_dev->close = w90p910_keypad_close;
|
|
|
|
input_dev->dev.parent = &pdev->dev;
|
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
input_dev->keycode = keypad->keymap;
|
|
|
|
input_dev->keycodesize = sizeof(keypad->keymap[0]);
|
|
|
|
input_dev->keycodemax = ARRAY_SIZE(keypad->keymap);
|
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
input_set_drvdata(input_dev, keypad);
|
|
|
|
|
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
|
2009-08-10 12:22:22 +08:00
|
|
|
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
|
|
|
|
|
2009-08-26 10:24:13 +08:00
|
|
|
matrix_keypad_build_keymap(keymap_data, W90P910_ROW_SHIFT,
|
|
|
|
input_dev->keycode, input_dev->keybit);
|
2009-08-10 12:22:22 +08:00
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
error = request_irq(keypad->irq, w90p910_keypad_irq_handler,
|
2011-09-08 05:04:16 +08:00
|
|
|
0, pdev->name, keypad);
|
2009-08-10 12:22:22 +08:00
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "failed to request IRQ\n");
|
2009-08-10 12:22:22 +08:00
|
|
|
goto failed_put_clk;
|
2009-08-10 12:22:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the input device */
|
|
|
|
error = input_register_device(input_dev);
|
|
|
|
if (error) {
|
|
|
|
dev_err(&pdev->dev, "failed to register input device\n");
|
|
|
|
goto failed_free_irq;
|
|
|
|
}
|
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
platform_set_drvdata(pdev, keypad);
|
2009-08-10 12:22:22 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed_free_irq:
|
|
|
|
free_irq(irq, pdev);
|
|
|
|
failed_put_clk:
|
|
|
|
clk_put(keypad->clk);
|
|
|
|
failed_free_io:
|
|
|
|
iounmap(keypad->mmio_base);
|
2009-08-10 12:22:22 +08:00
|
|
|
failed_free_res:
|
2009-08-10 12:22:22 +08:00
|
|
|
release_mem_region(res->start, resource_size(res));
|
|
|
|
failed_free:
|
2009-08-10 12:22:22 +08:00
|
|
|
input_free_device(input_dev);
|
2009-08-10 12:22:22 +08:00
|
|
|
kfree(keypad);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit w90p910_keypad_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct w90p910_keypad *keypad = platform_get_drvdata(pdev);
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
free_irq(keypad->irq, pdev);
|
|
|
|
|
|
|
|
clk_put(keypad->clk);
|
|
|
|
|
|
|
|
input_unregister_device(keypad->input_dev);
|
|
|
|
|
|
|
|
iounmap(keypad->mmio_base);
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
release_mem_region(res->start, resource_size(res));
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
kfree(keypad);
|
2009-08-10 12:22:22 +08:00
|
|
|
|
2009-08-10 12:22:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver w90p910_keypad_driver = {
|
|
|
|
.probe = w90p910_keypad_probe,
|
|
|
|
.remove = __devexit_p(w90p910_keypad_remove),
|
|
|
|
.driver = {
|
2010-07-19 13:23:19 +08:00
|
|
|
.name = "nuc900-kpi",
|
2009-08-10 12:22:22 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
2011-11-30 03:08:39 +08:00
|
|
|
module_platform_driver(w90p910_keypad_driver);
|
2009-08-10 12:22:22 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
|
2009-08-21 12:41:03 +08:00
|
|
|
MODULE_DESCRIPTION("w90p910 keypad driver");
|
2009-08-10 12:22:22 +08:00
|
|
|
MODULE_LICENSE("GPL");
|
2009-08-21 12:41:03 +08:00
|
|
|
MODULE_ALIAS("platform:nuc900-keypad");
|