mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +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>
260 lines
6.7 KiB
C
260 lines
6.7 KiB
C
/*
|
|
* Driver for the Freescale Semiconductor MC13783 touchscreen.
|
|
*
|
|
* Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
|
|
* Copyright (C) 2009 Sascha Hauer, Pengutronix
|
|
*
|
|
* Initial development of this code was funded by
|
|
* Phytec Messtechnik GmbH, http://www.phytec.de/
|
|
*
|
|
* 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 <linux/platform_device.h>
|
|
#include <linux/mfd/mc13783.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/input.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/init.h>
|
|
|
|
#define MC13783_TS_NAME "mc13783-ts"
|
|
|
|
#define DEFAULT_SAMPLE_TOLERANCE 300
|
|
|
|
static unsigned int sample_tolerance = DEFAULT_SAMPLE_TOLERANCE;
|
|
module_param(sample_tolerance, uint, S_IRUGO | S_IWUSR);
|
|
MODULE_PARM_DESC(sample_tolerance,
|
|
"If the minimal and maximal value read out for one axis (out "
|
|
"of three) differ by this value (default: "
|
|
__stringify(DEFAULT_SAMPLE_TOLERANCE) ") or more, the reading "
|
|
"is supposed to be wrong and is discarded. Set to 0 to "
|
|
"disable this check.");
|
|
|
|
struct mc13783_ts_priv {
|
|
struct input_dev *idev;
|
|
struct mc13783 *mc13783;
|
|
struct delayed_work work;
|
|
struct workqueue_struct *workq;
|
|
unsigned int sample[4];
|
|
};
|
|
|
|
static irqreturn_t mc13783_ts_handler(int irq, void *data)
|
|
{
|
|
struct mc13783_ts_priv *priv = data;
|
|
|
|
mc13783_irq_ack(priv->mc13783, irq);
|
|
|
|
/*
|
|
* Kick off reading coordinates. Note that if work happens already
|
|
* be queued for future execution (it rearms itself) it will not
|
|
* be rescheduled for immediate execution here. However the rearm
|
|
* delay is HZ / 50 which is acceptable.
|
|
*/
|
|
queue_delayed_work(priv->workq, &priv->work, 0);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
#define sort3(a0, a1, a2) ({ \
|
|
if (a0 > a1) \
|
|
swap(a0, a1); \
|
|
if (a1 > a2) \
|
|
swap(a1, a2); \
|
|
if (a0 > a1) \
|
|
swap(a0, a1); \
|
|
})
|
|
|
|
static void mc13783_ts_report_sample(struct mc13783_ts_priv *priv)
|
|
{
|
|
struct input_dev *idev = priv->idev;
|
|
int x0, x1, x2, y0, y1, y2;
|
|
int cr0, cr1;
|
|
|
|
/*
|
|
* the values are 10-bit wide only, but the two least significant
|
|
* bits are for future 12 bit use and reading yields 0
|
|
*/
|
|
x0 = priv->sample[0] & 0xfff;
|
|
x1 = priv->sample[1] & 0xfff;
|
|
x2 = priv->sample[2] & 0xfff;
|
|
y0 = priv->sample[3] & 0xfff;
|
|
y1 = (priv->sample[0] >> 12) & 0xfff;
|
|
y2 = (priv->sample[1] >> 12) & 0xfff;
|
|
cr0 = (priv->sample[2] >> 12) & 0xfff;
|
|
cr1 = (priv->sample[3] >> 12) & 0xfff;
|
|
|
|
dev_dbg(&idev->dev,
|
|
"x: (% 4d,% 4d,% 4d) y: (% 4d, % 4d,% 4d) cr: (% 4d, % 4d)\n",
|
|
x0, x1, x2, y0, y1, y2, cr0, cr1);
|
|
|
|
sort3(x0, x1, x2);
|
|
sort3(y0, y1, y2);
|
|
|
|
cr0 = (cr0 + cr1) / 2;
|
|
|
|
if (!cr0 || !sample_tolerance ||
|
|
(x2 - x0 < sample_tolerance &&
|
|
y2 - y0 < sample_tolerance)) {
|
|
/* report the median coordinate and average pressure */
|
|
if (cr0) {
|
|
input_report_abs(idev, ABS_X, x1);
|
|
input_report_abs(idev, ABS_Y, y1);
|
|
|
|
dev_dbg(&idev->dev, "report (%d, %d, %d)\n",
|
|
x1, y1, 0x1000 - cr0);
|
|
queue_delayed_work(priv->workq, &priv->work, HZ / 50);
|
|
} else
|
|
dev_dbg(&idev->dev, "report release\n");
|
|
|
|
input_report_abs(idev, ABS_PRESSURE,
|
|
cr0 ? 0x1000 - cr0 : cr0);
|
|
input_report_key(idev, BTN_TOUCH, cr0);
|
|
input_sync(idev);
|
|
} else
|
|
dev_dbg(&idev->dev, "discard event\n");
|
|
}
|
|
|
|
static void mc13783_ts_work(struct work_struct *work)
|
|
{
|
|
struct mc13783_ts_priv *priv =
|
|
container_of(work, struct mc13783_ts_priv, work.work);
|
|
unsigned int mode = MC13783_ADC_MODE_TS;
|
|
unsigned int channel = 12;
|
|
|
|
if (mc13783_adc_do_conversion(priv->mc13783,
|
|
mode, channel, priv->sample) == 0)
|
|
mc13783_ts_report_sample(priv);
|
|
}
|
|
|
|
static int mc13783_ts_open(struct input_dev *dev)
|
|
{
|
|
struct mc13783_ts_priv *priv = input_get_drvdata(dev);
|
|
int ret;
|
|
|
|
mc13783_lock(priv->mc13783);
|
|
|
|
mc13783_irq_ack(priv->mc13783, MC13783_IRQ_TS);
|
|
|
|
ret = mc13783_irq_request(priv->mc13783, MC13783_IRQ_TS,
|
|
mc13783_ts_handler, MC13783_TS_NAME, priv);
|
|
if (ret)
|
|
goto out;
|
|
|
|
ret = mc13783_reg_rmw(priv->mc13783, MC13783_ADC0,
|
|
MC13783_ADC0_TSMOD_MASK, MC13783_ADC0_TSMOD0);
|
|
if (ret)
|
|
mc13783_irq_free(priv->mc13783, MC13783_IRQ_TS, priv);
|
|
out:
|
|
mc13783_unlock(priv->mc13783);
|
|
return ret;
|
|
}
|
|
|
|
static void mc13783_ts_close(struct input_dev *dev)
|
|
{
|
|
struct mc13783_ts_priv *priv = input_get_drvdata(dev);
|
|
|
|
mc13783_lock(priv->mc13783);
|
|
mc13783_reg_rmw(priv->mc13783, MC13783_ADC0,
|
|
MC13783_ADC0_TSMOD_MASK, 0);
|
|
mc13783_irq_free(priv->mc13783, MC13783_IRQ_TS, priv);
|
|
mc13783_unlock(priv->mc13783);
|
|
|
|
cancel_delayed_work_sync(&priv->work);
|
|
}
|
|
|
|
static int __init mc13783_ts_probe(struct platform_device *pdev)
|
|
{
|
|
struct mc13783_ts_priv *priv;
|
|
struct input_dev *idev;
|
|
int ret = -ENOMEM;
|
|
|
|
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
idev = input_allocate_device();
|
|
if (!priv || !idev)
|
|
goto err_free_mem;
|
|
|
|
INIT_DELAYED_WORK(&priv->work, mc13783_ts_work);
|
|
priv->mc13783 = dev_get_drvdata(pdev->dev.parent);
|
|
priv->idev = idev;
|
|
|
|
/*
|
|
* We need separate workqueue because mc13783_adc_do_conversion
|
|
* uses keventd and thus would deadlock.
|
|
*/
|
|
priv->workq = create_singlethread_workqueue("mc13783_ts");
|
|
if (!priv->workq)
|
|
goto err_free_mem;
|
|
|
|
idev->name = MC13783_TS_NAME;
|
|
idev->dev.parent = &pdev->dev;
|
|
|
|
idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
|
|
idev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
|
|
input_set_abs_params(idev, ABS_X, 0, 0xfff, 0, 0);
|
|
input_set_abs_params(idev, ABS_Y, 0, 0xfff, 0, 0);
|
|
input_set_abs_params(idev, ABS_PRESSURE, 0, 0xfff, 0, 0);
|
|
|
|
idev->open = mc13783_ts_open;
|
|
idev->close = mc13783_ts_close;
|
|
|
|
input_set_drvdata(idev, priv);
|
|
|
|
ret = input_register_device(priv->idev);
|
|
if (ret) {
|
|
dev_err(&pdev->dev,
|
|
"register input device failed with %d\n", ret);
|
|
goto err_destroy_wq;
|
|
}
|
|
|
|
platform_set_drvdata(pdev, priv);
|
|
return 0;
|
|
|
|
err_destroy_wq:
|
|
destroy_workqueue(priv->workq);
|
|
err_free_mem:
|
|
input_free_device(idev);
|
|
kfree(priv);
|
|
return ret;
|
|
}
|
|
|
|
static int __devexit mc13783_ts_remove(struct platform_device *pdev)
|
|
{
|
|
struct mc13783_ts_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
destroy_workqueue(priv->workq);
|
|
input_unregister_device(priv->idev);
|
|
kfree(priv);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver mc13783_ts_driver = {
|
|
.remove = __devexit_p(mc13783_ts_remove),
|
|
.driver = {
|
|
.owner = THIS_MODULE,
|
|
.name = MC13783_TS_NAME,
|
|
},
|
|
};
|
|
|
|
static int __init mc13783_ts_init(void)
|
|
{
|
|
return platform_driver_probe(&mc13783_ts_driver, &mc13783_ts_probe);
|
|
}
|
|
module_init(mc13783_ts_init);
|
|
|
|
static void __exit mc13783_ts_exit(void)
|
|
{
|
|
platform_driver_unregister(&mc13783_ts_driver);
|
|
}
|
|
module_exit(mc13783_ts_exit);
|
|
|
|
MODULE_DESCRIPTION("MC13783 input touchscreen driver");
|
|
MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_ALIAS("platform:" MC13783_TS_NAME);
|