2009-09-18 05:35:45 +00:00
|
|
|
/*
|
|
|
|
* mcs5000_ts.c - Touchscreen driver for MELFAS MCS-5000 controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Samsung Electronics Co.Ltd
|
|
|
|
* Author: Joonyoung Shim <jy0922.shim@samsung.com>
|
|
|
|
*
|
|
|
|
* Based on wm97xx-core.c
|
|
|
|
*
|
|
|
|
* 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/module.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/irq.h>
|
2017-05-22 23:26:56 +00:00
|
|
|
#include <linux/platform_data/mcs.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-09-18 05:35:45 +00:00
|
|
|
|
|
|
|
/* Registers */
|
|
|
|
#define MCS5000_TS_STATUS 0x00
|
|
|
|
#define STATUS_OFFSET 0
|
|
|
|
#define STATUS_NO (0 << STATUS_OFFSET)
|
|
|
|
#define STATUS_INIT (1 << STATUS_OFFSET)
|
|
|
|
#define STATUS_SENSING (2 << STATUS_OFFSET)
|
|
|
|
#define STATUS_COORD (3 << STATUS_OFFSET)
|
|
|
|
#define STATUS_GESTURE (4 << STATUS_OFFSET)
|
|
|
|
#define ERROR_OFFSET 4
|
|
|
|
#define ERROR_NO (0 << ERROR_OFFSET)
|
|
|
|
#define ERROR_POWER_ON_RESET (1 << ERROR_OFFSET)
|
|
|
|
#define ERROR_INT_RESET (2 << ERROR_OFFSET)
|
|
|
|
#define ERROR_EXT_RESET (3 << ERROR_OFFSET)
|
|
|
|
#define ERROR_INVALID_REG_ADDRESS (8 << ERROR_OFFSET)
|
|
|
|
#define ERROR_INVALID_REG_VALUE (9 << ERROR_OFFSET)
|
|
|
|
|
|
|
|
#define MCS5000_TS_OP_MODE 0x01
|
|
|
|
#define RESET_OFFSET 0
|
|
|
|
#define RESET_NO (0 << RESET_OFFSET)
|
|
|
|
#define RESET_EXT_SOFT (1 << RESET_OFFSET)
|
|
|
|
#define OP_MODE_OFFSET 1
|
|
|
|
#define OP_MODE_SLEEP (0 << OP_MODE_OFFSET)
|
|
|
|
#define OP_MODE_ACTIVE (1 << OP_MODE_OFFSET)
|
|
|
|
#define GESTURE_OFFSET 4
|
|
|
|
#define GESTURE_DISABLE (0 << GESTURE_OFFSET)
|
|
|
|
#define GESTURE_ENABLE (1 << GESTURE_OFFSET)
|
|
|
|
#define PROXIMITY_OFFSET 5
|
|
|
|
#define PROXIMITY_DISABLE (0 << PROXIMITY_OFFSET)
|
|
|
|
#define PROXIMITY_ENABLE (1 << PROXIMITY_OFFSET)
|
|
|
|
#define SCAN_MODE_OFFSET 6
|
|
|
|
#define SCAN_MODE_INTERRUPT (0 << SCAN_MODE_OFFSET)
|
|
|
|
#define SCAN_MODE_POLLING (1 << SCAN_MODE_OFFSET)
|
|
|
|
#define REPORT_RATE_OFFSET 7
|
|
|
|
#define REPORT_RATE_40 (0 << REPORT_RATE_OFFSET)
|
|
|
|
#define REPORT_RATE_80 (1 << REPORT_RATE_OFFSET)
|
|
|
|
|
|
|
|
#define MCS5000_TS_SENS_CTL 0x02
|
|
|
|
#define MCS5000_TS_FILTER_CTL 0x03
|
|
|
|
#define PRI_FILTER_OFFSET 0
|
|
|
|
#define SEC_FILTER_OFFSET 4
|
|
|
|
|
|
|
|
#define MCS5000_TS_X_SIZE_UPPER 0x08
|
|
|
|
#define MCS5000_TS_X_SIZE_LOWER 0x09
|
|
|
|
#define MCS5000_TS_Y_SIZE_UPPER 0x0A
|
|
|
|
#define MCS5000_TS_Y_SIZE_LOWER 0x0B
|
|
|
|
|
|
|
|
#define MCS5000_TS_INPUT_INFO 0x10
|
|
|
|
#define INPUT_TYPE_OFFSET 0
|
|
|
|
#define INPUT_TYPE_NONTOUCH (0 << INPUT_TYPE_OFFSET)
|
|
|
|
#define INPUT_TYPE_SINGLE (1 << INPUT_TYPE_OFFSET)
|
|
|
|
#define INPUT_TYPE_DUAL (2 << INPUT_TYPE_OFFSET)
|
|
|
|
#define INPUT_TYPE_PALM (3 << INPUT_TYPE_OFFSET)
|
|
|
|
#define INPUT_TYPE_PROXIMITY (7 << INPUT_TYPE_OFFSET)
|
|
|
|
#define GESTURE_CODE_OFFSET 3
|
|
|
|
#define GESTURE_CODE_NO (0 << GESTURE_CODE_OFFSET)
|
|
|
|
|
|
|
|
#define MCS5000_TS_X_POS_UPPER 0x11
|
|
|
|
#define MCS5000_TS_X_POS_LOWER 0x12
|
|
|
|
#define MCS5000_TS_Y_POS_UPPER 0x13
|
|
|
|
#define MCS5000_TS_Y_POS_LOWER 0x14
|
|
|
|
#define MCS5000_TS_Z_POS 0x15
|
|
|
|
#define MCS5000_TS_WIDTH 0x16
|
|
|
|
#define MCS5000_TS_GESTURE_VAL 0x17
|
|
|
|
#define MCS5000_TS_MODULE_REV 0x20
|
|
|
|
#define MCS5000_TS_FIRMWARE_VER 0x21
|
|
|
|
|
|
|
|
/* Touchscreen absolute values */
|
|
|
|
#define MCS5000_MAX_XC 0x3ff
|
|
|
|
#define MCS5000_MAX_YC 0x3ff
|
|
|
|
|
|
|
|
enum mcs5000_ts_read_offset {
|
|
|
|
READ_INPUT_INFO,
|
|
|
|
READ_X_POS_UPPER,
|
|
|
|
READ_X_POS_LOWER,
|
|
|
|
READ_Y_POS_UPPER,
|
|
|
|
READ_Y_POS_LOWER,
|
|
|
|
READ_BLOCK_SIZE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Each client has this additional data */
|
|
|
|
struct mcs5000_ts_data {
|
|
|
|
struct i2c_client *client;
|
|
|
|
struct input_dev *input_dev;
|
2010-07-04 08:21:25 +00:00
|
|
|
const struct mcs_platform_data *platform_data;
|
2009-09-18 05:35:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct mcs5000_ts_data *data = dev_id;
|
|
|
|
struct i2c_client *client = data->client;
|
|
|
|
u8 buffer[READ_BLOCK_SIZE];
|
|
|
|
int err;
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
|
|
|
|
err = i2c_smbus_read_i2c_block_data(client, MCS5000_TS_INPUT_INFO,
|
|
|
|
READ_BLOCK_SIZE, buffer);
|
|
|
|
if (err < 0) {
|
|
|
|
dev_err(&client->dev, "%s, err[%d]\n", __func__, err);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (buffer[READ_INPUT_INFO]) {
|
|
|
|
case INPUT_TYPE_NONTOUCH:
|
|
|
|
input_report_key(data->input_dev, BTN_TOUCH, 0);
|
|
|
|
input_sync(data->input_dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_TYPE_SINGLE:
|
|
|
|
x = (buffer[READ_X_POS_UPPER] << 8) | buffer[READ_X_POS_LOWER];
|
|
|
|
y = (buffer[READ_Y_POS_UPPER] << 8) | buffer[READ_Y_POS_LOWER];
|
|
|
|
|
|
|
|
input_report_key(data->input_dev, BTN_TOUCH, 1);
|
|
|
|
input_report_abs(data->input_dev, ABS_X, x);
|
|
|
|
input_report_abs(data->input_dev, ABS_Y, y);
|
|
|
|
input_sync(data->input_dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_TYPE_DUAL:
|
|
|
|
/* TODO */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_TYPE_PALM:
|
|
|
|
/* TODO */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INPUT_TYPE_PROXIMITY:
|
|
|
|
/* TODO */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_err(&client->dev, "Unknown ts input type %d\n",
|
|
|
|
buffer[READ_INPUT_INFO]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data,
|
|
|
|
const struct mcs_platform_data *platform_data)
|
2009-09-18 05:35:45 +00:00
|
|
|
{
|
|
|
|
struct i2c_client *client = data->client;
|
|
|
|
|
|
|
|
/* Touch reset & sleep mode */
|
|
|
|
i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE,
|
|
|
|
RESET_EXT_SOFT | OP_MODE_SLEEP);
|
|
|
|
|
|
|
|
/* Touch size */
|
|
|
|
i2c_smbus_write_byte_data(client, MCS5000_TS_X_SIZE_UPPER,
|
|
|
|
platform_data->x_size >> 8);
|
|
|
|
i2c_smbus_write_byte_data(client, MCS5000_TS_X_SIZE_LOWER,
|
|
|
|
platform_data->x_size & 0xff);
|
|
|
|
i2c_smbus_write_byte_data(client, MCS5000_TS_Y_SIZE_UPPER,
|
|
|
|
platform_data->y_size >> 8);
|
|
|
|
i2c_smbus_write_byte_data(client, MCS5000_TS_Y_SIZE_LOWER,
|
|
|
|
platform_data->y_size & 0xff);
|
|
|
|
|
|
|
|
/* Touch active mode & 80 report rate */
|
|
|
|
i2c_smbus_write_byte_data(data->client, MCS5000_TS_OP_MODE,
|
|
|
|
OP_MODE_ACTIVE | REPORT_RATE_80);
|
|
|
|
}
|
|
|
|
|
2012-11-24 05:38:25 +00:00
|
|
|
static int mcs5000_ts_probe(struct i2c_client *client,
|
2014-05-26 20:36:13 +00:00
|
|
|
const struct i2c_device_id *id)
|
2009-09-18 05:35:45 +00:00
|
|
|
{
|
2014-05-26 20:36:13 +00:00
|
|
|
const struct mcs_platform_data *pdata;
|
2009-09-18 05:35:45 +00:00
|
|
|
struct mcs5000_ts_data *data;
|
|
|
|
struct input_dev *input_dev;
|
2014-05-26 20:36:13 +00:00
|
|
|
int error;
|
2009-09-18 05:35:45 +00:00
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
pdata = dev_get_platdata(&client->dev);
|
|
|
|
if (!pdata)
|
2009-09-18 05:35:45 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
|
|
|
|
if (!data) {
|
2009-09-18 05:35:45 +00:00
|
|
|
dev_err(&client->dev, "Failed to allocate memory\n");
|
2014-05-26 20:36:13 +00:00
|
|
|
return -ENOMEM;
|
2009-09-18 05:35:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data->client = client;
|
2014-05-26 20:36:13 +00:00
|
|
|
|
|
|
|
input_dev = devm_input_allocate_device(&client->dev);
|
|
|
|
if (!input_dev) {
|
|
|
|
dev_err(&client->dev, "Failed to allocate input device\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2009-09-18 05:35:45 +00:00
|
|
|
|
2014-05-27 17:22:12 +00:00
|
|
|
input_dev->name = "MELFAS MCS-5000 Touchscreen";
|
2009-09-18 05:35:45 +00:00
|
|
|
input_dev->id.bustype = BUS_I2C;
|
|
|
|
input_dev->dev.parent = &client->dev;
|
|
|
|
|
|
|
|
__set_bit(EV_ABS, input_dev->evbit);
|
|
|
|
__set_bit(EV_KEY, input_dev->evbit);
|
|
|
|
__set_bit(BTN_TOUCH, input_dev->keybit);
|
|
|
|
input_set_abs_params(input_dev, ABS_X, 0, MCS5000_MAX_XC, 0, 0);
|
|
|
|
input_set_abs_params(input_dev, ABS_Y, 0, MCS5000_MAX_YC, 0, 0);
|
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
data->input_dev = input_dev;
|
2009-09-18 05:35:45 +00:00
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
if (pdata->cfg_pin)
|
|
|
|
pdata->cfg_pin();
|
2009-09-18 05:35:45 +00:00
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
error = devm_request_threaded_irq(&client->dev, client->irq,
|
|
|
|
NULL, mcs5000_ts_interrupt,
|
|
|
|
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
|
|
|
|
"mcs5000_ts", data);
|
|
|
|
if (error) {
|
2009-09-18 05:35:45 +00:00
|
|
|
dev_err(&client->dev, "Failed to register interrupt\n");
|
2014-05-26 20:36:13 +00:00
|
|
|
return error;
|
2009-09-18 05:35:45 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
error = input_register_device(data->input_dev);
|
|
|
|
if (error) {
|
|
|
|
dev_err(&client->dev, "Failed to register input device\n");
|
|
|
|
return error;
|
|
|
|
}
|
2009-09-18 05:35:45 +00:00
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
mcs5000_ts_phys_init(data, pdata);
|
2009-09-18 05:35:45 +00:00
|
|
|
i2c_set_clientdata(client, data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-30 18:34:49 +00:00
|
|
|
static int __maybe_unused mcs5000_ts_suspend(struct device *dev)
|
2009-09-18 05:35:45 +00:00
|
|
|
{
|
2011-01-07 07:01:03 +00:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
|
|
|
|
2009-09-18 05:35:45 +00:00
|
|
|
/* Touch sleep mode */
|
|
|
|
i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, OP_MODE_SLEEP);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-30 18:34:49 +00:00
|
|
|
static int __maybe_unused mcs5000_ts_resume(struct device *dev)
|
2009-09-18 05:35:45 +00:00
|
|
|
{
|
2011-01-07 07:01:03 +00:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
2009-09-18 05:35:45 +00:00
|
|
|
struct mcs5000_ts_data *data = i2c_get_clientdata(client);
|
2014-05-26 20:36:13 +00:00
|
|
|
const struct mcs_platform_data *pdata = dev_get_platdata(dev);
|
2009-09-18 05:35:45 +00:00
|
|
|
|
2014-05-26 20:36:13 +00:00
|
|
|
mcs5000_ts_phys_init(data, pdata);
|
2009-09-18 05:35:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-07 07:01:03 +00:00
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(mcs5000_ts_pm, mcs5000_ts_suspend, mcs5000_ts_resume);
|
2009-09-18 05:35:45 +00:00
|
|
|
|
|
|
|
static const struct i2c_device_id mcs5000_ts_id[] = {
|
|
|
|
{ "mcs5000_ts", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
|
|
|
|
|
|
|
|
static struct i2c_driver mcs5000_ts_driver = {
|
|
|
|
.probe = mcs5000_ts_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "mcs5000_ts",
|
2011-01-07 07:01:03 +00:00
|
|
|
.pm = &mcs5000_ts_pm,
|
2009-09-18 05:35:45 +00:00
|
|
|
},
|
|
|
|
.id_table = mcs5000_ts_id,
|
|
|
|
};
|
|
|
|
|
2012-03-17 06:05:41 +00:00
|
|
|
module_i2c_driver(mcs5000_ts_driver);
|
2009-09-18 05:35:45 +00:00
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
|
|
|
|
MODULE_DESCRIPTION("Touchscreen driver for MELFAS MCS-5000 controller");
|
|
|
|
MODULE_LICENSE("GPL");
|