Skip to contentSkip to conversation

Input: add touchscreen driver for MELFAS MCS-5000 controller

PATCH Superseded Joonyoung Shim 2 participants 7 messages May 11, 2009 – Jun 3, 2009

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: add touchscreen driver for MELFAS MCS-5000 controller

The MELPAS MCS-5000 is the touchscreen controller. The overview of this controller can see at the following website:

http://www.melfas.com/product/product01.asp?k_r=eng_

This patch supports only the i2c interface.

---
 drivers/input/touchscreen/Kconfig      |   12 +
 drivers/input/touchscreen/Makefile     |    1 +
 drivers/input/touchscreen/mcs5000_ts.c |  377 ++++++++++++++++++++++++++++++++
 include/linux/i2c/mcs5000_ts.h         |   11 +
 4 files changed, 401 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/mcs5000_ts.c
 create mode 100644 include/linux/i2c/mcs5000_ts.h
drivers/input/touchscreen/Kconfig +12 -0
index 82c388e..ac5ebb4 100644
@@ -481,4 +481,16 @@ config TOUCHSCREEN_TSC2007
 	  To compile this driver as a module, choose M here: the
 	  module will be called tsc2007.
 
+config TOUCHSCREEN_MCS5000
+	tristate "MELFAS MCS-5000 touchscreen"
+	depends on I2C
+	help
+	  Say Y here if you have the MELFAS MCS-5000 touchscreen controller
+	  chip in your system.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called mcs5000_ts.
+
 endif
drivers/input/touchscreen/Makefile +1 -0
index bef7415..5e4a9dd 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_TOUCHSCREEN_GUNZE)		+= gunze.o
 obj-$(CONFIG_TOUCHSCREEN_ELO)		+= elo.o
 obj-$(CONFIG_TOUCHSCREEN_FUJITSU)	+= fujitsu_ts.o
 obj-$(CONFIG_TOUCHSCREEN_INEXIO)	+= inexio.o
+obj-$(CONFIG_TOUCHSCREEN_MCS5000)	+= mcs5000_ts.o
 obj-$(CONFIG_TOUCHSCREEN_MIGOR)		+= migor_ts.o
 obj-$(CONFIG_TOUCHSCREEN_MTOUCH)	+= mtouch.o
 obj-$(CONFIG_TOUCHSCREEN_MK712)		+= mk712.o
drivers/input/touchscreen/mcs5000_ts.c new file +377 -0

377 lines not on this page · raw message

include/linux/i2c/mcs5000_ts.h new file +11 -0
new file mode 100644
index 0000000..69d92b6
@@ -0,0 +1,11 @@
+#ifndef __LINUX_MCS5000_TS_H
+#define __LINUX_MCS5000_TS_H
+
+/* platform data for the MELFAS MCS5000 touchscreen driver */
+struct mcs5000_ts_platform_data {
+	void (*set_pin)(void);
+	int x_size;
+	int y_size;
+};
+
+#endif	/* __LINUX_MCS5000_TS_H */
Signature · 1 line
1.6.0.4
maintainer
#1 lore raw

Hi,

Quoted 7 lines · Joonyoung Shim

The MELPAS MCS-5000 is the touchscreen controller. The overview of this controller can see at the following website:

http://www.melfas.com/product/product01.asp?k_r=eng_

This patch supports only the i2c interface.

Thank you for the patch. Some comments below.

drivers/input/touchscreen/mcs5000_ts.c line 110

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+
+/* Touchscreen absolute values */
+static int abs_x[3] = {0, 1024, 0};
+module_param_array(abs_x, int, NULL, 0);
+MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
+
+static int abs_y[3] = {0, 1024, 0};
+module_param_array(abs_y, int, NULL, 0);
+MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
+

Do we need to have these as module parameters give the fact that we can set them dynamically with EVIOCSABS? I'd =say they should go.

Quoted 36 lines
drivers/input/touchscreen/mcs5000_ts.c new file +36 -0
+static int abs_p[3] = {0, 256, 0};
+module_param_array(abs_p, int, NULL, 0);
+MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
+
+/* Each client has this additional data */
+struct mcs5000_ts_data {
+	struct i2c_client *client;
+	struct input_dev *input_dev;
+	struct work_struct ts_event_work;
+	struct mcs5000_ts_platform_data *platform_data;
+
+	unsigned int irq;
+};
+
+static struct i2c_driver mcs5000_ts_driver;
+
+static void mcs5000_ts_input_read(struct mcs5000_ts_data *data)
+{
+	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);
+		return;
+	}
+
+	switch (buffer[READ_INPUT_INFO]) {
+	case INPUT_TYPE_NONTOUCH:
+		input_report_abs(data->input_dev, ABS_PRESSURE, 0);
+		input_report_key(data->input_dev, BTN_TOUCH, 0);
+		input_sync(data->input_dev);

drivers/input/touchscreen/mcs5000_ts.c line 156

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+		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_report_abs(data->input_dev, ABS_PRESSURE,
+				DEFAULT_PRESSURE);

If the hardware does not support pressure reading don't fake it. BTN_TOUCH should be enough to signal touch.

Quoted 45 lines
drivers/input/touchscreen/mcs5000_ts.c new file +45 -0
+		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;
+	}
+}
+
+static void mcs5000_ts_irq_worker(struct work_struct *work)
+{
+	struct mcs5000_ts_data *data = container_of(work,
+			struct mcs5000_ts_data, ts_event_work);
+
+	mcs5000_ts_input_read(data);
+
+	enable_irq(data->irq);
+}
+
+static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
+{
+	struct mcs5000_ts_data *data = dev_id;
+
+	if (!work_pending(&data->ts_event_work)) {
+		disable_irq_nosync(data->irq);
+		schedule_work(&data->ts_event_work);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int mcs5000_ts_input_init(struct mcs5000_ts_data *data)
+{
+	struct input_dev *input_dev;
+	int ret = 0;
+

drivers/input/touchscreen/mcs5000_ts.c line 211

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+	INIT_WORK(&data->ts_event_work, mcs5000_ts_irq_worker);
+
+	data->input_dev = input_allocate_device();
+	if (data->input_dev == NULL) {
+		ret = -ENOMEM;
+		goto err_input;
+	}
+
+	input_dev = data->input_dev;
+	input_dev->name = "MELPAS MCS-5000 Touchscreen";

input_dev->id.bustype = BUS_I2C;
input_dev->dev.parent = <i2c device>;

drivers/input/touchscreen/mcs5000_ts.c line 219

Quoted 8 lines
drivers/input/touchscreen/mcs5000_ts.c new file +8 -0
+	set_bit(EV_ABS, input_dev->evbit);
+	set_bit(ABS_X, input_dev->absbit);
+	set_bit(ABS_Y, input_dev->absbit);
+	set_bit(ABS_PRESSURE, input_dev->absbit);
+	input_set_abs_params(input_dev, ABS_X, abs_x[0], abs_x[1], abs_x[2], 0);
+	input_set_abs_params(input_dev, ABS_Y, abs_y[0], abs_y[1], abs_y[2], 0);
+	input_set_abs_params(input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
+			abs_p[2], 0);

This line should go.

drivers/input/touchscreen/mcs5000_ts.c line 230

Quoted 11 lines
drivers/input/touchscreen/mcs5000_ts.c new file +11 -0
+	set_bit(EV_KEY, input_dev->evbit);
+	set_bit(BTN_TOUCH, input_dev->keybit);
+
+	ret = input_register_device(data->input_dev);
+	if (ret < 0)
+		goto err_register;
+
+	if (request_irq(data->irq, mcs5000_ts_interrupt,
+			IRQF_TRIGGER_LOW, "mcs5000_ts_input", data)) {
+		dev_err(&data->client->dev, "Failed to register interrupt\n");
+		ret = -EINVAL;

Why EINVAL and not EBUSY? Or better yet, why don't you propagate what reqiest_irq returned?

drivers/input/touchscreen/mcs5000_ts.c line 240

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+		goto err_irq;
+	}
+
+	input_set_drvdata(input_dev, data);
+
+	return 0;
+err_irq:
+	input_unregister_device(data->input_dev);
+err_register:
+	input_free_device(data->input_dev);

Do not call input_free_device() after input_unregister_device(), it will cause double-free. EIther rearrange initialization order or do data->input_dev = NULL; right after calling input_unregister_device().

Quoted 20 lines
drivers/input/touchscreen/mcs5000_ts.c new file +20 -0
+err_input:
+	return ret;
+}
+
+static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data)
+{
+	struct i2c_client *client = data->client;
+	struct mcs5000_ts_platform_data *platform_data = data->platform_data;
+
+	/* 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);

drivers/input/touchscreen/mcs5000_ts.c line 270

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+	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);
+}
+
+static int mcs5000_ts_probe(struct i2c_client *client,
+		const struct i2c_device_id *idp)

This should be marked __devinit.

Quoted 26 lines
drivers/input/touchscreen/mcs5000_ts.c new file +26 -0
+{
+	struct mcs5000_ts_data *data;
+	int ret;
+
+	data = kzalloc(sizeof(struct mcs5000_ts_data), GFP_KERNEL);
+	if (!data)
+		dev_err(&client->dev, "Failed to allocate driver data\n");
+		ret = -ENOMEM;
+		goto exit;
+	}
+
+	data->client = client;
+	data->irq = client->irq;
+	data->platform_data = client->dev.platform_data;
+
+	i2c_set_clientdata(client, data);
+
+	if (data->platform_data->set_pin)
+		data->platform_data->set_pin();
+
+	ret = mcs5000_ts_input_init(data);
+	if (ret)
+		goto exit_free;
+
+	mcs5000_ts_phys_init(data);
+

drivers/input/touchscreen/mcs5000_ts.c line 306

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+	return 0;
+
+exit_free:
+	kfree(data);
+	i2c_set_clientdata(client, NULL);
+exit:
+	return ret;
+}
+
+static int mcs5000_ts_remove(struct i2c_client *client)

This should be marked __devexit.

drivers/input/touchscreen/mcs5000_ts.c line 310

Quoted 4 lines
drivers/input/touchscreen/mcs5000_ts.c new file +4 -0
+{
+	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
+
+	cancel_work_sync(&data->ts_event_work);

There is a race here, IRQ handler may resubmit work after cancel_work_sync() returns. You need to make sure that IRQ handler does not resubmit work while device is being shut down.

drivers/input/touchscreen/mcs5000_ts.c line 313

Quoted 3 lines
drivers/input/touchscreen/mcs5000_ts.c new file +3 -0
+	free_irq(data->irq, data);
+	input_unregister_device(data->input_dev);
+	input_free_device(data->input_dev);

Just input_unregister_device() is enough.

Quoted 32 lines
drivers/input/touchscreen/mcs5000_ts.c new file +32 -0
+	kfree(data);
+
+	i2c_set_clientdata(client, NULL);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int mcs5000_ts_suspend(struct i2c_client *client, pm_message_t mesg)
+{
+	/* Touch sleep mode */
+	i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, OP_MODE_SLEEP);
+
+	return 0;
+}
+
+static int mcs5000_ts_resume(struct i2c_client *client)
+{
+	struct mcs5000_ts_data *data;
+
+	data = i2c_get_clientdata(client);
+	mcs5000_ts_phys_init(data);
+
+	return 0;
+}
+#else
+#define mcs5000_ts_suspend	NULL
+#define mcs5000_ts_resume	NULL
+#endif
+
+static const struct i2c_device_id mcs5000_ts_id[] = {
+	{ "mcs5000_ts", 0 },

drivers/input/touchscreen/mcs5000_ts.c line 355

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
+
+static struct i2c_driver mcs5000_ts_driver = {
+	.driver = {
+		.name = "mcs5000_ts",
+	},
+	.probe		= mcs5000_ts_probe,
+	.remove		= mcs5000_ts_remove,

__devexit_p()

#ifdef CONFIG_PM

drivers/input/touchscreen/mcs5000_ts.c line 357

Quoted 2 lines
drivers/input/touchscreen/mcs5000_ts.c new file +2 -0
+	.suspend	= mcs5000_ts_suspend,
+	.resume		= mcs5000_ts_resume,

#endif

drivers/input/touchscreen/mcs5000_ts.c line 360

Quoted 3 lines
drivers/input/touchscreen/mcs5000_ts.c new file +3 -0
+	.id_table	= mcs5000_ts_id,
+};
+

Thanks.

Signature · 1 line
Dmitry
#2 lore raw

Hi,

Thank you for your review.

Quoted 13 lines

Hi,

Quoted 7 lines · Joonyoung Shim

The MELPAS MCS-5000 is the touchscreen controller. The overview of this controller can see at the following website:

http://www.melfas.com/product/product01.asp?k_r=eng_

This patch supports only the i2c interface.

Thank you for the patch. Some comments below.

Quoted 13 lines

drivers/input/touchscreen/mcs5000_ts.c line 110

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+
+/* Touchscreen absolute values */
+static int abs_x[3] = {0, 1024, 0};
+module_param_array(abs_x, int, NULL, 0);
+MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
+
+static int abs_y[3] = {0, 1024, 0};
+module_param_array(abs_y, int, NULL, 0);
+MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
+

Do we need to have these as module parameters give the fact that we can set them dynamically with EVIOCSABS? I'd =say they should go.

I think that this part is unnecessary, we can get resolution of touchscreen from platform_data or i will use the defined values.

Quoted 42 lines
Quoted 42 lines
drivers/input/touchscreen/mcs5000_ts.c new file +41 -0
+static int abs_p[3] = {0, 256, 0};
+module_param_array(abs_p, int, NULL, 0);
+MODULE_PARM_DESC(abs_p, "Touchscreen absolute Pressure min, max, fuzz");
+
+/* Each client has this additional data */
+struct mcs5000_ts_data {
+	struct i2c_client *client;
+	struct input_dev *input_dev;
+	struct work_struct ts_event_work;
+	struct mcs5000_ts_platform_data *platform_data;
+
+	unsigned int irq;
+};
+
+static struct i2c_driver mcs5000_ts_driver;
+
+static void mcs5000_ts_input_read(struct mcs5000_ts_data *data)
+{
+	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);
+		return;
+	}
+
+	switch (buffer[READ_INPUT_INFO]) {
+	case INPUT_TYPE_NONTOUCH:
+		input_report_abs(data->input_dev, ABS_PRESSURE, 0);
+		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];
+
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 156

Quoted 5 lines
drivers/input/touchscreen/mcs5000_ts.c new file +5 -0
+		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_report_abs(data->input_dev, ABS_PRESSURE,
+				DEFAULT_PRESSURE);

If the hardware does not support pressure reading don't fake it. BTN_TOUCH should be enough to signal touch.

MCS-5000 supports pressure reading, but the value of pressure is unstable in my target, so i used the static value defined.
I will add pressure reading after more test.

signal touch? Do you mean single touch?

Quoted 51 lines
Quoted 51 lines
drivers/input/touchscreen/mcs5000_ts.c new file +50 -0
+		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;
+	}
+}
+
+static void mcs5000_ts_irq_worker(struct work_struct *work)
+{
+	struct mcs5000_ts_data *data = container_of(work,
+			struct mcs5000_ts_data, ts_event_work);
+
+	mcs5000_ts_input_read(data);
+
+	enable_irq(data->irq);
+}
+
+static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
+{
+	struct mcs5000_ts_data *data = dev_id;
+
+	if (!work_pending(&data->ts_event_work)) {
+		disable_irq_nosync(data->irq);
+		schedule_work(&data->ts_event_work);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int mcs5000_ts_input_init(struct mcs5000_ts_data *data)
+{
+	struct input_dev *input_dev;
+	int ret = 0;
+
+	INIT_WORK(&data->ts_event_work, mcs5000_ts_irq_worker);
+
+	data->input_dev = input_allocate_device();
+	if (data->input_dev == NULL) {
+		ret = -ENOMEM;
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 211

Quoted 5 lines
drivers/input/touchscreen/mcs5000_ts.c new file +5 -0
+		goto err_input;
+	}
+
+	input_dev = data->input_dev;
+	input_dev->name = "MELPAS MCS-5000 Touchscreen";

input_dev->id.bustype = BUS_I2C;
input_dev->dev.parent = <i2c device>;

ok, i will add it.

Quoted 13 lines

drivers/input/touchscreen/mcs5000_ts.c line 219

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +8 -0
+	set_bit(EV_ABS, input_dev->evbit);
+	set_bit(ABS_X, input_dev->absbit);
+	set_bit(ABS_Y, input_dev->absbit);
+	set_bit(ABS_PRESSURE, input_dev->absbit);
+	input_set_abs_params(input_dev, ABS_X, abs_x[0], abs_x[1], abs_x[2], 0);
+	input_set_abs_params(input_dev, ABS_Y, abs_y[0], abs_y[1], abs_y[2], 0);
+	input_set_abs_params(input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
+			abs_p[2], 0);

This line should go.

Quoted 14 lines

drivers/input/touchscreen/mcs5000_ts.c line 230

Quoted 11 lines
drivers/input/touchscreen/mcs5000_ts.c new file +11 -0
+	set_bit(EV_KEY, input_dev->evbit);
+	set_bit(BTN_TOUCH, input_dev->keybit);
+
+	ret = input_register_device(data->input_dev);
+	if (ret < 0)
+		goto err_register;
+
+	if (request_irq(data->irq, mcs5000_ts_interrupt,
+			IRQF_TRIGGER_LOW, "mcs5000_ts_input", data)) {
+		dev_err(&data->client->dev, "Failed to register interrupt\n");
+		ret = -EINVAL;

Why EINVAL and not EBUSY? Or better yet, why don't you propagate what reqiest_irq returned?

Hmm, EINVAL is used in wm97xx-core.c file, but you are right. I will fix it using the latter.

Quoted 15 lines

drivers/input/touchscreen/mcs5000_ts.c line 240

Quoted 11 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+		goto err_irq;
+	}
+
+	input_set_drvdata(input_dev, data);
+
+	return 0;
+err_irq:
+	input_unregister_device(data->input_dev);
+err_register:
+	input_free_device(data->input_dev);

Do not call input_free_device() after input_unregister_device(), it will cause double-free. EIther rearrange initialization order or do data->input_dev = NULL; right after calling input_unregister_device().

ok, i will fix it.

Quoted 25 lines
Quoted 25 lines
drivers/input/touchscreen/mcs5000_ts.c new file +24 -0
+err_input:
+	return ret;
+}
+
+static void mcs5000_ts_phys_init(struct mcs5000_ts_data *data)
+{
+	struct i2c_client *client = data->client;
+	struct mcs5000_ts_platform_data *platform_data = data->platform_data;
+
+	/* 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 */
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 270

Quoted 6 lines
drivers/input/touchscreen/mcs5000_ts.c new file +6 -0
+	i2c_smbus_write_byte_data(data->client, MCS5000_TS_OP_MODE,
+			OP_MODE_ACTIVE | REPORT_RATE_80);
+}
+
+static int mcs5000_ts_probe(struct i2c_client *client,
+		const struct i2c_device_id *idp)

This should be marked __devinit.

ok, i will add it.

Quoted 31 lines
Quoted 31 lines
drivers/input/touchscreen/mcs5000_ts.c new file +30 -0
+{
+	struct mcs5000_ts_data *data;
+	int ret;
+
+	data = kzalloc(sizeof(struct mcs5000_ts_data), GFP_KERNEL);
+	if (!data)
+		dev_err(&client->dev, "Failed to allocate driver data\n");
+		ret = -ENOMEM;
+		goto exit;
+	}
+
+	data->client = client;
+	data->irq = client->irq;
+	data->platform_data = client->dev.platform_data;
+
+	i2c_set_clientdata(client, data);
+
+	if (data->platform_data->set_pin)
+		data->platform_data->set_pin();
+
+	ret = mcs5000_ts_input_init(data);
+	if (ret)
+		goto exit_free;
+
+	mcs5000_ts_phys_init(data);
+
+	return 0;
+
+exit_free:
+	kfree(data);
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 306

Quoted 6 lines
drivers/input/touchscreen/mcs5000_ts.c new file +6 -0
+	i2c_set_clientdata(client, NULL);
+exit:
+	return ret;
+}
+
+static int mcs5000_ts_remove(struct i2c_client *client)

This should be marked __devexit.

ok, i will add it.

Quoted 9 lines

drivers/input/touchscreen/mcs5000_ts.c line 310

Quoted 5 lines
drivers/input/touchscreen/mcs5000_ts.c new file +4 -0
+{
+	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
+
+	cancel_work_sync(&data->ts_event_work);

There is a race here, IRQ handler may resubmit work after cancel_work_sync() returns. You need to make sure that IRQ handler does not resubmit work while device is being shut down.

ok, how about doing free_irq() before cancel_work_sync() call?

Quoted 6 lines

drivers/input/touchscreen/mcs5000_ts.c line 313

Quoted 4 lines
drivers/input/touchscreen/mcs5000_ts.c new file +3 -0
+	free_irq(data->irq, data);
+	input_unregister_device(data->input_dev);
+	input_free_device(data->input_dev);

Just input_unregister_device() is enough.

ok.

Quoted 37 lines
Quoted 37 lines
drivers/input/touchscreen/mcs5000_ts.c new file +36 -0
+	kfree(data);
+
+	i2c_set_clientdata(client, NULL);
+
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int mcs5000_ts_suspend(struct i2c_client *client, pm_message_t mesg)
+{
+	/* Touch sleep mode */
+	i2c_smbus_write_byte_data(client, MCS5000_TS_OP_MODE, OP_MODE_SLEEP);
+
+	return 0;
+}
+
+static int mcs5000_ts_resume(struct i2c_client *client)
+{
+	struct mcs5000_ts_data *data;
+
+	data = i2c_get_clientdata(client);
+	mcs5000_ts_phys_init(data);
+
+	return 0;
+}
+#else
+#define mcs5000_ts_suspend	NULL
+#define mcs5000_ts_resume	NULL
+#endif
+
+static const struct i2c_device_id mcs5000_ts_id[] = {
+	{ "mcs5000_ts", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, mcs5000_ts_id);
+
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 355

Quoted 6 lines
drivers/input/touchscreen/mcs5000_ts.c new file +6 -0
+static struct i2c_driver mcs5000_ts_driver = {
+	.driver = {
+		.name = "mcs5000_ts",
+	},
+	.probe		= mcs5000_ts_probe,
+	.remove		= mcs5000_ts_remove,

__devexit_p()

ok.

Quoted 5 lines

#ifdef CONFIG_PM

drivers/input/touchscreen/mcs5000_ts.c line 357

Quoted 2 lines
drivers/input/touchscreen/mcs5000_ts.c new file +2 -0
+	.suspend	= mcs5000_ts_suspend,
+	.resume		= mcs5000_ts_resume,

#endif

ok, i will add it.

Quoted 7 lines

drivers/input/touchscreen/mcs5000_ts.c line 360

Quoted 4 lines
drivers/input/touchscreen/mcs5000_ts.c new file +3 -0
+	.id_table	= mcs5000_ts_id,
+};
+

Thanks.

Thanks, too.

maintainer
#3 lore raw
Quoted 31 lines · Joonyoung Shim

Hi,

Thank you for your review.

Quoted 13 lines

Hi,

Quoted 7 lines · Joonyoung Shim

The MELPAS MCS-5000 is the touchscreen controller. The overview of this controller can see at the following website:

http://www.melfas.com/product/product01.asp?k_r=eng_

This patch supports only the i2c interface.

Thank you for the patch. Some comments below.

Quoted 13 lines

drivers/input/touchscreen/mcs5000_ts.c line 110

Quoted 10 lines
drivers/input/touchscreen/mcs5000_ts.c new file +10 -0
+
+/* Touchscreen absolute values */
+static int abs_x[3] = {0, 1024, 0};
+module_param_array(abs_x, int, NULL, 0);
+MODULE_PARM_DESC(abs_x, "Touchscreen absolute X min, max, fuzz");
+
+static int abs_y[3] = {0, 1024, 0};
+module_param_array(abs_y, int, NULL, 0);
+MODULE_PARM_DESC(abs_y, "Touchscreen absolute Y min, max, fuzz");
+

Do we need to have these as module parameters give the fact that we can set them dynamically with EVIOCSABS? I'd =say they should go.

Quoted 3 lines

I think that this part is unnecessary, we can get resolution of touchscreen from platform_data or i will use the defined values.

Ok, that would work as well.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/input/touchscreen/mcs5000_ts.c new file +4 -0
+	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];
+
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 156

Quoted 5 lines
drivers/input/touchscreen/mcs5000_ts.c new file +5 -0
+		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_report_abs(data->input_dev, ABS_PRESSURE,
+				DEFAULT_PRESSURE);

If the hardware does not support pressure reading don't fake it. BTN_TOUCH should be enough to signal touch.

Quoted 3 lines

MCS-5000 supports pressure reading, but the value of pressure is unstable in my target, so i used the static value defined.
I will add pressure reading after more test.

OK. Alternatively you may indicate in the platform data if pressure reading is supported and set ABS_PRESSURE bit and report pressure only when you know it works well.

Quoted 2 lines

signal touch? Do you mean single touch?

I meant "signal" as "convey", "indicate".

Quoted 10 lines
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 230

Quoted 5 lines
drivers/input/touchscreen/mcs5000_ts.c new file +5 -0
+
+	if (request_irq(data->irq, mcs5000_ts_interrupt,
+			IRQF_TRIGGER_LOW, "mcs5000_ts_input", data)) {
+		dev_err(&data->client->dev, "Failed to register interrupt\n");
+		ret = -EINVAL;

Why EINVAL and not EBUSY? Or better yet, why don't you propagate what reqiest_irq returned?

Hmm, EINVAL is used in wm97xx-core.c file, but you are right.

I am always taking patches ;))

Quoted 11 lines
Quoted 10 lines

drivers/input/touchscreen/mcs5000_ts.c line 310

Quoted 6 lines
drivers/input/touchscreen/mcs5000_ts.c new file +4 -0
+{
+	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
+
+	cancel_work_sync(&data->ts_event_work);

There is a race here, IRQ handler may resubmit work after cancel_work_sync() returns. You need to make sure that IRQ handler does not resubmit work while device is being shut down.

Quoted 2 lines

ok, how about doing free_irq() before cancel_work_sync() call?

Then there is a risk that your work will try to enable_irq() on irq that was freed. I am not sure if IRQ core will be happy with it,

Signature · 1 line
Dmitry
#4 lore raw
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/input/touchscreen/mcs5000_ts.c line 156

Quoted 9 lines
drivers/input/touchscreen/mcs5000_ts.c new file +9 -0
+	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_report_abs(data->input_dev, ABS_PRESSURE,
+				DEFAULT_PRESSURE);

If the hardware does not support pressure reading don't fake it. BTN_TOUCH should be enough to signal touch.

Quoted 7 lines
Quoted 3 lines

MCS-5000 supports pressure reading, but the value of pressure is unstable in my target, so i used the static value defined.
I will add pressure reading after more test.

OK. Alternatively you may indicate in the platform data if pressure reading is supported and set ABS_PRESSURE bit and report pressure only when you know it works well.

OK, i will add the thing about pressure in the platform data.

Quoted 3 lines
Quoted 1 line

signal touch? Do you mean single touch?

I meant "signal" as "convey", "indicate".

I see :)

Quoted 11 lines
Quoted 9 lines
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 230

Quoted 6 lines
drivers/input/touchscreen/mcs5000_ts.c new file +5 -0
+
+	if (request_irq(data->irq, mcs5000_ts_interrupt,
+			IRQF_TRIGGER_LOW, "mcs5000_ts_input", data)) {
+		dev_err(&data->client->dev, "Failed to register interrupt\n");
+		ret = -EINVAL;

Why EINVAL and not EBUSY? Or better yet, why don't you propagate what reqiest_irq returned?

Hmm, EINVAL is used in wm97xx-core.c file, but you are right.

I am always taking patches ;))

OK, i will send the patch about it.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 310

Quoted 5 lines
drivers/input/touchscreen/mcs5000_ts.c new file +4 -0
+{
+	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
+
+	cancel_work_sync(&data->ts_event_work);

There is a race here, IRQ handler may resubmit work after cancel_work_sync() returns. You need to make sure that IRQ handler does not resubmit work while device is being shut down.

Quoted 5 lines
Quoted 2 lines

ok, how about doing free_irq() before cancel_work_sync() call?

Then there is a risk that your work will try to enable_irq() on irq that was freed. I am not sure if IRQ core will be happy with it,

Oh, i didn't think about that, then, how about the following patch? The work handler decides trying to enable_irq() by whether irq is NULL or not.

@@ -179,7 +179,8 @@ static void mcs5000_ts_irq_worker(struct work_struct *work)

mcs5000_ts_input_read(data);

- enable_irq(data->irq);
+ if (data->irq)
+ enable_irq(data->irq);
}

static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)
@@ -307,8 +308,9 @@ static int mcs5000_ts_remove(struct i2c_client *client)
{
struct mcs5000_ts_data *data = i2c_get_clientdata(client);

- cancel_work_sync(&data->ts_event_work);
free_irq(data->irq, data);
+ data->irq = 0;
+ cancel_work_sync(&data->ts_event_work);
input_unregister_device(data->input_dev);
input_free_device(data->input_dev);
kfree(data);

maintainer
#5 lore raw
Quoted 74 lines · On Thursday 14 May 2009 17:49:40 Joonyoung Shim wrote:
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

drivers/input/touchscreen/mcs5000_ts.c line 156

Quoted 9 lines
drivers/input/touchscreen/mcs5000_ts.c new file +9 -0
+	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_report_abs(data->input_dev, ABS_PRESSURE,
+				DEFAULT_PRESSURE);

If the hardware does not support pressure reading don't fake it. BTN_TOUCH should be enough to signal touch.

Quoted 7 lines
Quoted 3 lines

MCS-5000 supports pressure reading, but the value of pressure is unstable in my target, so i used the static value defined. I will add pressure reading after more test.

OK. Alternatively you may indicate in the platform data if pressure reading is supported and set ABS_PRESSURE bit and report pressure only when you know it works well.

OK, i will add the thing about pressure in the platform data.

Quoted 3 lines
Quoted 1 line

signal touch? Do you mean single touch?

I meant "signal" as "convey", "indicate".

I see :)

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 230

Quoted 5 lines
drivers/input/touchscreen/mcs5000_ts.c new file +5 -0
+
+	if (request_irq(data->irq, mcs5000_ts_interrupt,
+			IRQF_TRIGGER_LOW, "mcs5000_ts_input", data)) {
+		dev_err(&data->client->dev, "Failed to register interrupt\n");
+		ret = -EINVAL;

Why EINVAL and not EBUSY? Or better yet, why don't you propagate what reqiest_irq returned?

Quoted 3 lines
Quoted 1 line

Hmm, EINVAL is used in wm97xx-core.c file, but you are right.

I am always taking patches ;))

OK, i will send the patch about it.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

drivers/input/touchscreen/mcs5000_ts.c line 310

Quoted 4 lines
drivers/input/touchscreen/mcs5000_ts.c new file +4 -0
+{
+	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
+
+	cancel_work_sync(&data->ts_event_work);

There is a race here, IRQ handler may resubmit work after cancel_work_sync() returns. You need to make sure that IRQ handler does not resubmit work while device is being shut down.

Quoted 4 lines
Quoted 1 line

ok, how about doing free_irq() before cancel_work_sync() call?

Then there is a risk that your work will try to enable_irq() on irq that was freed. I am not sure if IRQ core will be happy with it,

Oh, i didn't think about that, then, how about the following patch? The work handler decides trying to enable_irq() by whether irq is NULL or not.

(quoted diff) +2 -1
@@ -179,7 +179,8 @@ static void mcs5000_ts_irq_worker(struct work_struct
 *work)
 
 	mcs5000_ts_input_read(data);
 
-	enable_irq(data->irq);
+	if (data->irq)
+		enable_irq(data->irq);
 }
 

static irqreturn_t mcs5000_ts_interrupt(int irq, void *dev_id)

Review static int mcs5000_ts_remove(struct i2c_client *client) · line 312

Quoted 6 lines
(quoted diff) +1 -1
@@ -307,8 +308,9 @@ static int mcs5000_ts_remove(struct i2c_client *client)
 {
 	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
 
-	cancel_work_sync(&data->ts_event_work);
 	free_irq(data->irq, data);
+	data->irq = 0;

Not if you want to enable IRQ 0 every once in a while. I think a separate flag, the check in the IRQ handler as opposed to workqueue handler and a memory barrier should work though.

Quoted 4 lines
(quoted diff) +1 -0
+	cancel_work_sync(&data->ts_event_work);
 	input_unregister_device(data->input_dev);
 	input_free_device(data->input_dev);
 	kfree(data);
Signature · 1 line
Dmitry
#6 lore raw
In reply to Dmitry Torokhov

Hi, sorry for long time no reponse.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/input/touchscreen/mcs5000_ts.c line 156

Quoted 9 lines
drivers/input/touchscreen/mcs5000_ts.c new file +9 -0
+	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_report_abs(data->input_dev, ABS_PRESSURE,
+				DEFAULT_PRESSURE);

If the hardware does not support pressure reading don't fake it. BTN_TOUCH should be enough to signal touch.

Quoted 7 lines
Quoted 3 lines

MCS-5000 supports pressure reading, but the value of pressure is unstable in my target, so i used the static value defined.
I will add pressure reading after more test.

OK. Alternatively you may indicate in the platform data if pressure reading is supported and set ABS_PRESSURE bit and report pressure only when you know it works well.

This is my mistake, the MCS-5000 does not support pressure. I confused pressure and proximity.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/input/touchscreen/mcs5000_ts.c line 310

Quoted 4 lines
drivers/input/touchscreen/mcs5000_ts.c new file +4 -0
+{
+	struct mcs5000_ts_data *data = i2c_get_clientdata(client);
+
+	cancel_work_sync(&data->ts_event_work);

There is a race here, IRQ handler may resubmit work after cancel_work_sync() returns. You need to make sure that IRQ handler does not resubmit work while device is being shut down.

Quoted 6 lines
Quoted 2 lines

ok, how about doing free_irq() before cancel_work_sync() call?

Then there is a risk that your work will try to enable_irq() on irq that was freed. I am not sure if IRQ core will be happy with it,

It is no problem to try to enable_irq() on irq that was freed, but a new problem is balance of disable_irq() and enable_irq().
I refered drivers/net/phy/phy.c file.

I will post patch v2.

thanks.