mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-21 08:53:41 +00:00
5a0e3ad6af
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>
347 lines
9.2 KiB
C
347 lines
9.2 KiB
C
/*
|
|
* DaVinci Key Scan Driver for TI platforms
|
|
*
|
|
* Copyright (C) 2009 Texas Instruments, Inc
|
|
*
|
|
* Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
|
|
*
|
|
* Intial Code: Sandeep Paulraj <s-paulraj@ti.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; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/types.h>
|
|
#include <linux/input.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <mach/hardware.h>
|
|
#include <mach/irqs.h>
|
|
#include <mach/keyscan.h>
|
|
|
|
/* Key scan registers */
|
|
#define DAVINCI_KEYSCAN_KEYCTRL 0x0000
|
|
#define DAVINCI_KEYSCAN_INTENA 0x0004
|
|
#define DAVINCI_KEYSCAN_INTFLAG 0x0008
|
|
#define DAVINCI_KEYSCAN_INTCLR 0x000c
|
|
#define DAVINCI_KEYSCAN_STRBWIDTH 0x0010
|
|
#define DAVINCI_KEYSCAN_INTERVAL 0x0014
|
|
#define DAVINCI_KEYSCAN_CONTTIME 0x0018
|
|
#define DAVINCI_KEYSCAN_CURRENTST 0x001c
|
|
#define DAVINCI_KEYSCAN_PREVSTATE 0x0020
|
|
#define DAVINCI_KEYSCAN_EMUCTRL 0x0024
|
|
#define DAVINCI_KEYSCAN_IODFTCTRL 0x002c
|
|
|
|
/* Key Control Register (KEYCTRL) */
|
|
#define DAVINCI_KEYSCAN_KEYEN 0x00000001
|
|
#define DAVINCI_KEYSCAN_PREVMODE 0x00000002
|
|
#define DAVINCI_KEYSCAN_CHATOFF 0x00000004
|
|
#define DAVINCI_KEYSCAN_AUTODET 0x00000008
|
|
#define DAVINCI_KEYSCAN_SCANMODE 0x00000010
|
|
#define DAVINCI_KEYSCAN_OUTTYPE 0x00000020
|
|
|
|
/* Masks for the interrupts */
|
|
#define DAVINCI_KEYSCAN_INT_CONT 0x00000008
|
|
#define DAVINCI_KEYSCAN_INT_OFF 0x00000004
|
|
#define DAVINCI_KEYSCAN_INT_ON 0x00000002
|
|
#define DAVINCI_KEYSCAN_INT_CHANGE 0x00000001
|
|
#define DAVINCI_KEYSCAN_INT_ALL 0x0000000f
|
|
|
|
struct davinci_ks {
|
|
struct input_dev *input;
|
|
struct davinci_ks_platform_data *pdata;
|
|
int irq;
|
|
void __iomem *base;
|
|
resource_size_t pbase;
|
|
size_t base_size;
|
|
unsigned short keymap[];
|
|
};
|
|
|
|
/* Initializing the kp Module */
|
|
static int __init davinci_ks_initialize(struct davinci_ks *davinci_ks)
|
|
{
|
|
struct device *dev = &davinci_ks->input->dev;
|
|
struct davinci_ks_platform_data *pdata = davinci_ks->pdata;
|
|
u32 matrix_ctrl;
|
|
|
|
/* Enable all interrupts */
|
|
__raw_writel(DAVINCI_KEYSCAN_INT_ALL,
|
|
davinci_ks->base + DAVINCI_KEYSCAN_INTENA);
|
|
|
|
/* Clear interrupts if any */
|
|
__raw_writel(DAVINCI_KEYSCAN_INT_ALL,
|
|
davinci_ks->base + DAVINCI_KEYSCAN_INTCLR);
|
|
|
|
/* Setup the scan period = strobe + interval */
|
|
__raw_writel(pdata->strobe,
|
|
davinci_ks->base + DAVINCI_KEYSCAN_STRBWIDTH);
|
|
__raw_writel(pdata->interval,
|
|
davinci_ks->base + DAVINCI_KEYSCAN_INTERVAL);
|
|
__raw_writel(0x01,
|
|
davinci_ks->base + DAVINCI_KEYSCAN_CONTTIME);
|
|
|
|
/* Define matrix type */
|
|
switch (pdata->matrix_type) {
|
|
case DAVINCI_KEYSCAN_MATRIX_4X4:
|
|
matrix_ctrl = 0;
|
|
break;
|
|
case DAVINCI_KEYSCAN_MATRIX_5X3:
|
|
matrix_ctrl = (1 << 6);
|
|
break;
|
|
default:
|
|
dev_err(dev->parent, "wrong matrix type\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Enable key scan module and set matrix type */
|
|
__raw_writel(DAVINCI_KEYSCAN_AUTODET | DAVINCI_KEYSCAN_KEYEN |
|
|
matrix_ctrl, davinci_ks->base + DAVINCI_KEYSCAN_KEYCTRL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static irqreturn_t davinci_ks_interrupt(int irq, void *dev_id)
|
|
{
|
|
struct davinci_ks *davinci_ks = dev_id;
|
|
struct device *dev = &davinci_ks->input->dev;
|
|
unsigned short *keymap = davinci_ks->keymap;
|
|
int keymapsize = davinci_ks->pdata->keymapsize;
|
|
u32 prev_status, new_status, changed;
|
|
bool release;
|
|
int keycode = KEY_UNKNOWN;
|
|
int i;
|
|
|
|
/* Disable interrupt */
|
|
__raw_writel(0x0, davinci_ks->base + DAVINCI_KEYSCAN_INTENA);
|
|
|
|
/* Reading previous and new status of the key scan */
|
|
prev_status = __raw_readl(davinci_ks->base + DAVINCI_KEYSCAN_PREVSTATE);
|
|
new_status = __raw_readl(davinci_ks->base + DAVINCI_KEYSCAN_CURRENTST);
|
|
|
|
changed = prev_status ^ new_status;
|
|
|
|
if (changed) {
|
|
/*
|
|
* It goes through all bits in 'changed' to ensure
|
|
* that no key changes are being missed
|
|
*/
|
|
for (i = 0 ; i < keymapsize; i++) {
|
|
if ((changed>>i) & 0x1) {
|
|
keycode = keymap[i];
|
|
release = (new_status >> i) & 0x1;
|
|
dev_dbg(dev->parent, "key %d %s\n", keycode,
|
|
release ? "released" : "pressed");
|
|
input_report_key(davinci_ks->input, keycode,
|
|
!release);
|
|
input_sync(davinci_ks->input);
|
|
}
|
|
}
|
|
/* Clearing interrupt */
|
|
__raw_writel(DAVINCI_KEYSCAN_INT_ALL,
|
|
davinci_ks->base + DAVINCI_KEYSCAN_INTCLR);
|
|
}
|
|
|
|
/* Enable interrupts */
|
|
__raw_writel(0x1, davinci_ks->base + DAVINCI_KEYSCAN_INTENA);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static int __init davinci_ks_probe(struct platform_device *pdev)
|
|
{
|
|
struct davinci_ks *davinci_ks;
|
|
struct input_dev *key_dev;
|
|
struct resource *res, *mem;
|
|
struct device *dev = &pdev->dev;
|
|
struct davinci_ks_platform_data *pdata = pdev->dev.platform_data;
|
|
int error, i;
|
|
|
|
if (pdata->device_enable) {
|
|
error = pdata->device_enable(dev);
|
|
if (error < 0) {
|
|
dev_dbg(dev, "device enable function failed\n");
|
|
return error;
|
|
}
|
|
}
|
|
|
|
if (!pdata->keymap) {
|
|
dev_dbg(dev, "no keymap from pdata\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
davinci_ks = kzalloc(sizeof(struct davinci_ks) +
|
|
sizeof(unsigned short) * pdata->keymapsize, GFP_KERNEL);
|
|
if (!davinci_ks) {
|
|
dev_dbg(dev, "could not allocate memory for private data\n");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
memcpy(davinci_ks->keymap, pdata->keymap,
|
|
sizeof(unsigned short) * pdata->keymapsize);
|
|
|
|
key_dev = input_allocate_device();
|
|
if (!key_dev) {
|
|
dev_dbg(dev, "could not allocate input device\n");
|
|
error = -ENOMEM;
|
|
goto fail1;
|
|
}
|
|
|
|
davinci_ks->input = key_dev;
|
|
|
|
davinci_ks->irq = platform_get_irq(pdev, 0);
|
|
if (davinci_ks->irq < 0) {
|
|
dev_err(dev, "no key scan irq\n");
|
|
error = davinci_ks->irq;
|
|
goto fail2;
|
|
}
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!res) {
|
|
dev_err(dev, "no mem resource\n");
|
|
error = -EINVAL;
|
|
goto fail2;
|
|
}
|
|
|
|
davinci_ks->pbase = res->start;
|
|
davinci_ks->base_size = resource_size(res);
|
|
|
|
mem = request_mem_region(davinci_ks->pbase, davinci_ks->base_size,
|
|
pdev->name);
|
|
if (!mem) {
|
|
dev_err(dev, "key scan registers at %08x are not free\n",
|
|
davinci_ks->pbase);
|
|
error = -EBUSY;
|
|
goto fail2;
|
|
}
|
|
|
|
davinci_ks->base = ioremap(davinci_ks->pbase, davinci_ks->base_size);
|
|
if (!davinci_ks->base) {
|
|
dev_err(dev, "can't ioremap MEM resource.\n");
|
|
error = -ENOMEM;
|
|
goto fail3;
|
|
}
|
|
|
|
/* Enable auto repeat feature of Linux input subsystem */
|
|
if (pdata->rep)
|
|
__set_bit(EV_REP, key_dev->evbit);
|
|
|
|
/* Setup input device */
|
|
__set_bit(EV_KEY, key_dev->evbit);
|
|
|
|
/* Setup the platform data */
|
|
davinci_ks->pdata = pdata;
|
|
|
|
for (i = 0; i < davinci_ks->pdata->keymapsize; i++)
|
|
__set_bit(davinci_ks->pdata->keymap[i], key_dev->keybit);
|
|
|
|
key_dev->name = "davinci_keyscan";
|
|
key_dev->phys = "davinci_keyscan/input0";
|
|
key_dev->dev.parent = &pdev->dev;
|
|
key_dev->id.bustype = BUS_HOST;
|
|
key_dev->id.vendor = 0x0001;
|
|
key_dev->id.product = 0x0001;
|
|
key_dev->id.version = 0x0001;
|
|
key_dev->keycode = davinci_ks->keymap;
|
|
key_dev->keycodesize = sizeof(davinci_ks->keymap[0]);
|
|
key_dev->keycodemax = davinci_ks->pdata->keymapsize;
|
|
|
|
error = input_register_device(davinci_ks->input);
|
|
if (error < 0) {
|
|
dev_err(dev, "unable to register davinci key scan device\n");
|
|
goto fail4;
|
|
}
|
|
|
|
error = request_irq(davinci_ks->irq, davinci_ks_interrupt,
|
|
IRQF_DISABLED, pdev->name, davinci_ks);
|
|
if (error < 0) {
|
|
dev_err(dev, "unable to register davinci key scan interrupt\n");
|
|
goto fail5;
|
|
}
|
|
|
|
error = davinci_ks_initialize(davinci_ks);
|
|
if (error < 0) {
|
|
dev_err(dev, "unable to initialize davinci key scan device\n");
|
|
goto fail6;
|
|
}
|
|
|
|
platform_set_drvdata(pdev, davinci_ks);
|
|
return 0;
|
|
|
|
fail6:
|
|
free_irq(davinci_ks->irq, davinci_ks);
|
|
fail5:
|
|
input_unregister_device(davinci_ks->input);
|
|
key_dev = NULL;
|
|
fail4:
|
|
iounmap(davinci_ks->base);
|
|
fail3:
|
|
release_mem_region(davinci_ks->pbase, davinci_ks->base_size);
|
|
fail2:
|
|
input_free_device(key_dev);
|
|
fail1:
|
|
kfree(davinci_ks);
|
|
|
|
return error;
|
|
}
|
|
|
|
static int __devexit davinci_ks_remove(struct platform_device *pdev)
|
|
{
|
|
struct davinci_ks *davinci_ks = platform_get_drvdata(pdev);
|
|
|
|
free_irq(davinci_ks->irq, davinci_ks);
|
|
|
|
input_unregister_device(davinci_ks->input);
|
|
|
|
iounmap(davinci_ks->base);
|
|
release_mem_region(davinci_ks->pbase, davinci_ks->base_size);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
kfree(davinci_ks);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver davinci_ks_driver = {
|
|
.driver = {
|
|
.name = "davinci_keyscan",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.remove = __devexit_p(davinci_ks_remove),
|
|
};
|
|
|
|
static int __init davinci_ks_init(void)
|
|
{
|
|
return platform_driver_probe(&davinci_ks_driver, davinci_ks_probe);
|
|
}
|
|
module_init(davinci_ks_init);
|
|
|
|
static void __exit davinci_ks_exit(void)
|
|
{
|
|
platform_driver_unregister(&davinci_ks_driver);
|
|
}
|
|
module_exit(davinci_ks_exit);
|
|
|
|
MODULE_AUTHOR("Miguel Aguilar");
|
|
MODULE_DESCRIPTION("Texas Instruments DaVinci Key Scan Driver");
|
|
MODULE_LICENSE("GPL");
|