|
|
|
/*
|
|
|
|
* Touchscreen driver for Marvell 88PM860x
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Marvell International Ltd.
|
|
|
|
* Haojian Zhuang <haojian.zhuang@marvell.com>
|
|
|
|
*
|
|
|
|
* 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/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/mfd/88pm860x.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>
15 years ago
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#define MEAS_LEN (8)
|
|
|
|
#define ACCURATE_BIT (12)
|
|
|
|
|
|
|
|
/* touch register */
|
|
|
|
#define MEAS_EN3 (0x52)
|
|
|
|
|
|
|
|
#define MEAS_TSIX_1 (0x8D)
|
|
|
|
#define MEAS_TSIX_2 (0x8E)
|
|
|
|
#define MEAS_TSIY_1 (0x8F)
|
|
|
|
#define MEAS_TSIY_2 (0x90)
|
|
|
|
#define MEAS_TSIZ1_1 (0x91)
|
|
|
|
#define MEAS_TSIZ1_2 (0x92)
|
|
|
|
#define MEAS_TSIZ2_1 (0x93)
|
|
|
|
#define MEAS_TSIZ2_2 (0x94)
|
|
|
|
|
|
|
|
/* bit definitions of touch */
|
|
|
|
#define MEAS_PD_EN (1 << 3)
|
|
|
|
#define MEAS_TSIX_EN (1 << 4)
|
|
|
|
#define MEAS_TSIY_EN (1 << 5)
|
|
|
|
#define MEAS_TSIZ1_EN (1 << 6)
|
|
|
|
#define MEAS_TSIZ2_EN (1 << 7)
|
|
|
|
|
|
|
|
struct pm860x_touch {
|
|
|
|
struct input_dev *idev;
|
|
|
|
struct i2c_client *i2c;
|
|
|
|
struct pm860x_chip *chip;
|
|
|
|
int irq;
|
|
|
|
int res_x; /* resistor of Xplate */
|
|
|
|
};
|
|
|
|
|
|
|
|
static irqreturn_t pm860x_touch_handler(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct pm860x_touch *touch = data;
|
|
|
|
struct pm860x_chip *chip = touch->chip;
|
|
|
|
unsigned char buf[MEAS_LEN];
|
|
|
|
int x, y, pen_down;
|
|
|
|
int z1, z2, rt = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pm860x_bulk_read(touch->i2c, MEAS_TSIX_1, MEAS_LEN, buf);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
pen_down = buf[1] & (1 << 6);
|
|
|
|
x = ((buf[0] & 0xFF) << 4) | (buf[1] & 0x0F);
|
|
|
|
y = ((buf[2] & 0xFF) << 4) | (buf[3] & 0x0F);
|
|
|
|
z1 = ((buf[4] & 0xFF) << 4) | (buf[5] & 0x0F);
|
|
|
|
z2 = ((buf[6] & 0xFF) << 4) | (buf[7] & 0x0F);
|
|
|
|
|
|
|
|
if (pen_down) {
|
|
|
|
if ((x != 0) && (z1 != 0) && (touch->res_x != 0)) {
|
|
|
|
rt = z2 / z1 - 1;
|
|
|
|
rt = (rt * touch->res_x * x) >> ACCURATE_BIT;
|
|
|
|
dev_dbg(chip->dev, "z1:%d, z2:%d, rt:%d\n",
|
|
|
|
z1, z2, rt);
|
|
|
|
}
|
|
|
|
input_report_abs(touch->idev, ABS_X, x);
|
|
|
|
input_report_abs(touch->idev, ABS_Y, y);
|
|
|
|
input_report_abs(touch->idev, ABS_PRESSURE, rt);
|
|
|
|
input_report_key(touch->idev, BTN_TOUCH, 1);
|
|
|
|
dev_dbg(chip->dev, "pen down at [%d, %d].\n", x, y);
|
|
|
|
} else {
|
|
|
|
input_report_abs(touch->idev, ABS_PRESSURE, 0);
|
|
|
|
input_report_key(touch->idev, BTN_TOUCH, 0);
|
|
|
|
dev_dbg(chip->dev, "pen release\n");
|
|
|
|
}
|
|
|
|
input_sync(touch->idev);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pm860x_touch_open(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct pm860x_touch *touch = input_get_drvdata(dev);
|
|
|
|
int data, ret;
|
|
|
|
|
|
|
|
data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
|
|
|
|
| MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
|
|
|
|
ret = pm860x_set_bits(touch->i2c, MEAS_EN3, data, data);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pm860x_touch_close(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct pm860x_touch *touch = input_get_drvdata(dev);
|
|
|
|
int data;
|
|
|
|
|
|
|
|
data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN
|
|
|
|
| MEAS_TSIZ1_EN | MEAS_TSIZ2_EN;
|
|
|
|
pm860x_set_bits(touch->i2c, MEAS_EN3, data, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devinit pm860x_touch_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
|
|
|
|
struct pm860x_platform_data *pm860x_pdata = \
|
|
|
|
pdev->dev.parent->platform_data;
|
|
|
|
struct pm860x_touch_pdata *pdata = NULL;
|
|
|
|
struct pm860x_touch *touch;
|
|
|
|
int irq, ret;
|
|
|
|
|
|
|
|
irq = platform_get_irq(pdev, 0);
|
|
|
|
if (irq < 0) {
|
|
|
|
dev_err(&pdev->dev, "No IRQ resource!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pm860x_pdata) {
|
|
|
|
dev_err(&pdev->dev, "platform data is missing\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata = pm860x_pdata->touch;
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->dev, "touchscreen data is missing\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
touch = kzalloc(sizeof(struct pm860x_touch), GFP_KERNEL);
|
|
|
|
if (touch == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
dev_set_drvdata(&pdev->dev, touch);
|
|
|
|
|
|
|
|
touch->idev = input_allocate_device();
|
|
|
|
if (touch->idev == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate input device!\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
touch->idev->name = "88pm860x-touch";
|
|
|
|
touch->idev->phys = "88pm860x/input0";
|
|
|
|
touch->idev->id.bustype = BUS_I2C;
|
|
|
|
touch->idev->dev.parent = &pdev->dev;
|
|
|
|
touch->idev->open = pm860x_touch_open;
|
|
|
|
touch->idev->close = pm860x_touch_close;
|
|
|
|
touch->chip = chip;
|
|
|
|
touch->i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
|
|
|
|
touch->irq = irq + chip->irq_base;
|
|
|
|
touch->res_x = pdata->res_x;
|
|
|
|
input_set_drvdata(touch->idev, touch);
|
|
|
|
|
|
|
|
ret = request_threaded_irq(touch->irq, NULL, pm860x_touch_handler,
|
|
|
|
IRQF_ONESHOT, "touch", touch);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_irq;
|
|
|
|
|
|
|
|
__set_bit(EV_ABS, touch->idev->evbit);
|
|
|
|
__set_bit(ABS_X, touch->idev->absbit);
|
|
|
|
__set_bit(ABS_Y, touch->idev->absbit);
|
|
|
|
__set_bit(ABS_PRESSURE, touch->idev->absbit);
|
|
|
|
__set_bit(EV_SYN, touch->idev->evbit);
|
|
|
|
__set_bit(EV_KEY, touch->idev->evbit);
|
|
|
|
__set_bit(BTN_TOUCH, touch->idev->keybit);
|
|
|
|
|
|
|
|
input_set_abs_params(touch->idev, ABS_X, 0, 1 << ACCURATE_BIT, 0, 0);
|
|
|
|
input_set_abs_params(touch->idev, ABS_Y, 0, 1 << ACCURATE_BIT, 0, 0);
|
|
|
|
input_set_abs_params(touch->idev, ABS_PRESSURE, 0, 1 << ACCURATE_BIT,
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
ret = input_register_device(touch->idev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(chip->dev, "Failed to register touch!\n");
|
|
|
|
goto out_rg;
|
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, touch);
|
|
|
|
return 0;
|
|
|
|
out_rg:
|
|
|
|
free_irq(touch->irq, touch);
|
|
|
|
out_irq:
|
|
|
|
input_free_device(touch->idev);
|
|
|
|
out:
|
|
|
|
kfree(touch);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit pm860x_touch_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct pm860x_touch *touch = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
input_unregister_device(touch->idev);
|
|
|
|
free_irq(touch->irq, touch);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
kfree(touch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver pm860x_touch_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "88pm860x-touch",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = pm860x_touch_probe,
|
|
|
|
.remove = __devexit_p(pm860x_touch_remove),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pm860x_touch_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&pm860x_touch_driver);
|
|
|
|
}
|
|
|
|
module_init(pm860x_touch_init);
|
|
|
|
|
|
|
|
static void __exit pm860x_touch_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&pm860x_touch_driver);
|
|
|
|
}
|
|
|
|
module_exit(pm860x_touch_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Touchscreen driver for Marvell Semiconductor 88PM860x");
|
|
|
|
MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:88pm860x-touch");
|
|
|
|
|