Skip to contentSkip to conversation

input: enable touch on 88pm860x

PATCH New Haojian Zhuang 3 participants 8 messages Nov 13, 2009 – Nov 20, 2009

lore
Share & tools
lore
#1 lore raw

PATCH 9/10 input: enable touch on 88pm860x

Review

Quoted 4 lines · Haojian Zhuang
(quoted diff) +4 -0
+	} else {
+		input_report_abs(touch->idev, ABS_PRESSURE, 0);
+		input_report_abs(touch->idev, ABS_TOOL_WIDTH, 1);
+		input_report_abs(touch->idev, BTN_TOUCH, 0);

This appears to be the only place ABS_TOOL_WIDTH is reported - could it not just be omitted?

#2 lore raw

PATCH 9/10 input: enable touch on 88pm860x

In reply to Haojian Zhuang

Hi Haojian,

Quoted 77 lines · Haojian Zhuang

From 122d2c29ffef393b533628c2be8bdb308220331f Mon Sep 17 00:00:00 2001
From: Haojian Zhuang <[email protected]>
Date: Thu, 12 Nov 2009 12:15:51 -0500
Subject: [PATCH] input: enable touch on 88pm860x

---
 drivers/input/touchscreen/88pm860x-ts.c |  222 +++++++++++++++++++++++++++++++
 drivers/input/touchscreen/Kconfig       |    7 +
 drivers/input/touchscreen/Makefile      |    1 +
 3 files changed, 230 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/touchscreen/88pm860x-ts.c
drivers/input/touchscreen/88pm860x-ts.c new file +57 -0
new file mode 100644
index 0000000..b65ef13
@@ -0,0 +1,222 @@
+/*
+ * Touchscreen driver for Marvell 88PM860x
+ *
+ * Copyright (C) 2009 Marvell International Ltd.
+ * 	Haojian Zhuang <[email protected]>
+ *
+ * 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/input.h>
+#include <linux/mfd/88pm860x.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)
+
+struct pm860x_touch {
+	struct input_dev *idev;
+	struct pm860x_chip *chip;
+	int irq;
+	int count;	/* record open count */
+};
+
+static void pm860x_touch_handler(struct pm860x_chip *chip, int irq, void *data)
+{
+	struct pm860x_touch *touch = data;
+	unsigned char buf[MEAS_LEN];
+	int x, y, pen_down;
+	int ret;
+
+	pm860x_mask_irq(chip, irq);
+	ret = pm860x_bulk_read(chip->parent, DESC_8607, MEAS_TSIX_1,
+				MEAS_LEN, buf);
+	if (ret < 0)
+		goto out;
+
+	pen_down = buf[1] & (1 << 6);

drivers/input/touchscreen/88pm860x-ts.c line 67

Quoted 10 lines
drivers/input/touchscreen/88pm860x-ts.c new file +10 -0
+	x = ((buf[0] & 0xFF) << 4) | (buf[1] & 0x0F);
+	y = ((buf[2] & 0xFF) << 4) | (buf[3] & 0x0F);
+
+	if (pen_down) {
+		input_report_abs(touch->idev, ABS_X, x);
+		input_report_abs(touch->idev, ABS_Y, y);
+		input_report_abs(touch->idev, ABS_PRESSURE, 255);
+		input_report_abs(touch->idev, BTN_TOUCH, 1);
+	} else {
+		input_report_abs(touch->idev, ABS_PRESSURE, 0);

Your device does not seem to be reporting real pressure so please don't fake ABS_PRESSURE events.

drivers/input/touchscreen/88pm860x-ts.c line 68

Quoted 1 line
drivers/input/touchscreen/88pm860x-ts.c new file +1 -0
+		input_report_abs(touch->idev, ABS_TOOL_WIDTH, 1);

This event is used to report size of the touching object, if you don't know it do not report.

drivers/input/touchscreen/88pm860x-ts.c line 69

Quoted 1 line
drivers/input/touchscreen/88pm860x-ts.c new file +1 -0
+		input_report_abs(touch->idev, BTN_TOUCH, 0);

There certainly isn't EV_ABS/BTN_TOUCH event, you meant to use input_report_key().

Quoted 9 lines
drivers/input/touchscreen/88pm860x-ts.c new file +9 -0
+	}
+	input_sync(touch->idev);
+	pm860x_unmask_irq(chip, irq);
+
+	if (pen_down)
+		dev_dbg(chip->dev, "pen down at [%d, %d]\n", x, y);
+	else
+		dev_dbg(chip->dev, "pen release\n");
+out:

drivers/input/touchscreen/88pm860x-ts.c line 88

Quoted 10 lines
drivers/input/touchscreen/88pm860x-ts.c new file +10 -0
+	return;
+}
+
+static int pm860x_touch_open(struct input_dev *dev)
+{
+	struct pm860x_touch *touch = input_get_drvdata(dev);
+	struct pm860x_chip *chip = touch->chip;
+	int data, ret;
+
+	if (++touch->count) {

Input core takes care to call open only when first client opens the device, no need to count here.

Quoted 9 lines
drivers/input/touchscreen/88pm860x-ts.c new file +9 -0
+		data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN;
+		ret = pm860x_set_bits(chip->parent, DESC_8607, MEAS_EN3,
+					data, data);
+		if (ret < 0)
+			goto out;
+		pm860x_unmask_irq(chip, touch->irq);
+	}
+	return 0;
+out:

drivers/input/touchscreen/88pm860x-ts.c line 107

Quoted 10 lines
drivers/input/touchscreen/88pm860x-ts.c new file +10 -0
+	return ret;
+}
+
+static void pm860x_touch_close(struct input_dev *dev)
+{
+	struct pm860x_touch *touch = input_get_drvdata(dev);
+	struct pm860x_chip *chip = touch->chip;
+	int data;
+
+	if (--touch->count == 0) {

Same goes for close.

Quoted 16 lines
drivers/input/touchscreen/88pm860x-ts.c new file +16 -0
+		data = MEAS_PD_EN | MEAS_TSIX_EN | MEAS_TSIY_EN;
+		pm860x_set_bits(chip->parent, DESC_8607, MEAS_EN3,
+				data, 0);
+		pm860x_mask_irq(chip, touch->irq);
+	}
+}
+
+static int __devinit pm860x_touch_probe(struct platform_device *pdev)
+{
+	struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent);
+	struct pm860x_plat_data *pm860x_pdata;
+	struct pm860x_touch_pdata *pdata;
+	struct pm860x_touch *touch;
+	int irq, ret;
+
+	irq = platform_get_irq(pdev, 0);

drivers/input/touchscreen/88pm860x-ts.c line 133

Quoted 10 lines
drivers/input/touchscreen/88pm860x-ts.c new file +10 -0
+	if (irq < 0) {
+		dev_err(&pdev->dev, "No IRQ resource!\n");
+		return -EINVAL;
+	}
+
+	if (pdev->dev.parent->platform_data) {
+		pm860x_pdata = pdev->dev.parent->platform_data;
+		pdata = pm860x_pdata->touch;
+	} else
+		pdata = NULL;

I don't see pdata being used...

Quoted 23 lines
drivers/input/touchscreen/88pm860x-ts.c new file +23 -0
+
+	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->dev.parent = &pdev->dev;
+	touch->idev->open = pm860x_touch_open;
+	touch->idev->close = pm860x_touch_close;
+	touch->chip = chip;
+	touch->irq = irq;
+	touch->count = 0;
+	input_set_drvdata(touch->idev, touch);
+
+	ret = pm860x_request_irq(chip, irq, pm860x_touch_handler, touch);

drivers/input/touchscreen/88pm860x-ts.c line 166

Quoted 10 lines
drivers/input/touchscreen/88pm860x-ts.c new file +10 -0
+	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);

__set_bit(), no need to lock the bus. Also temprary for input device looks more pleasing to an eye and probably saves a couple of bytes.

Quoted 28 lines
drivers/input/touchscreen/88pm860x-ts.c new file +28 -0
+
+	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, 255, 0, 0);
+	input_set_abs_params(touch->idev, ABS_TOOL_WIDTH, 0, 15, 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:
+	pm860x_free_irq(chip, irq);
+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);

drivers/input/touchscreen/88pm860x-ts.c line 204

Quoted 10 lines
drivers/input/touchscreen/88pm860x-ts.c new file +10 -0
+	return 0;
+}
+
+static struct platform_driver pm860x_touch_driver = {
+	.driver	= {
+		.name	= "88pm860x-touch",
+		.owner	= THIS_MODULE,
+	},
+	.probe	= pm860x_touch_probe,
+	.remove	= pm860x_touch_remove,

__devexit_p()

Quoted 24 lines
drivers/input/touchscreen/88pm860x-ts.c new file +18 -0
+};
+
+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 <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:88pm860x-touch");
drivers/input/touchscreen/Kconfig +0 -0
index 8cc453c..0b06a53 100644

drivers/input/touchscreen/Kconfig config TOUCHSCREEN_PCAP · line 539

Quoted 10 lines
drivers/input/touchscreen/Kconfig +7 -0
@@ -530,4 +530,11 @@ config TOUCHSCREEN_PCAP
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called pcap_ts.
+
+config TOUCHSCREEN_88PM860X
+	bool "Marvell 88PM860x touchscreen"
+	depends on MFD_88PM860X
+	help
+	  Say Y here if you have a 88PM860x PMIC and want to enable
+	  support for the built-in touchscreen.

No module option?

Quoted 7 lines
drivers/input/touchscreen/Kconfig +0 -0
 endif
drivers/input/touchscreen/Makefile +0 -0
index 15fa62c..9180479 100644
@@ -42,3 +42,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE)	+=
Quoted 5 lines

mainstone-wm97xx.o
obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o
obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o
obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o
+obj-$(CONFIG_TOUCHSCREEN_88PM860X) += 88pm860x-ts.o

Would appreciate if you arrange makefile alphabetically.

Thanks.

Signature · 1 line
Dmitry
#3 lore raw

PATCH 9/10 input: enable touch on 88pm860x

Quoted 75 lines · Dmitry Torokhov

Hi Haojian,

Quoted 2 lines · Haojian Zhuang

From 122d2c29ffef393b533628c2be8bdb308220331f Mon Sep 17 00:00:00 2001
+ ? ? ? ? ? ? input_report_abs(touch->idev, ABS_PRESSURE, 0);

Your device does not seem to be reporting real pressure so please don't fake ABS_PRESSURE events.

Quoted 1 line

+ ? ? ? ? ? ? input_report_abs(touch->idev, ABS_TOOL_WIDTH, 1);

This event is used to report size of the touching object, if you don't know it do not report.

Quoted 1 line

+ ? ? ? ? ? ? input_report_abs(touch->idev, BTN_TOUCH, 0);

There certainly isn't EV_ABS/BTN_TOUCH event, you meant to use input_report_key().

Quoted 2 lines

+
+ ? ? if (++touch->count) {

Input core takes care to call open only when first client opens the device, no need to count here.

Quoted 1 line

+ ? ? if (--touch->count == 0) {

Same goes for close.

Quoted 6 lines

+
+ ? ? if (pdev->dev.parent->platform_data) {
+ ? ? ? ? ? ? pm860x_pdata = pdev->dev.parent->platform_data;
+ ? ? ? ? ? ? pdata = pm860x_pdata->touch;
+ ? ? } else
+ ? ? ? ? ? ? pdata = NULL;

I don't see pdata being used...

Quoted 5 lines

+
+ ? ? 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);

__set_bit(), no need to lock the bus. Also temprary for input device looks more pleasing to an eye and probably saves a couple of bytes.

Quoted 4 lines

+
+ ? ? },
+ ? ? .probe ?= pm860x_touch_probe,
+ ? ? .remove = pm860x_touch_remove,

__devexit_p()

Review

Quoted 8 lines
(quoted diff) +8 -0
+};
+
+config TOUCHSCREEN_88PM860X
+ ? ? bool "Marvell 88PM860x touchscreen"
+ ? ? depends on MFD_88PM860X
+ ? ? help
+ ? ? ? Say Y here if you have a 88PM860x PMIC and want to enable
+ ? ? ? support for the built-in touchscreen.

No module option?

Quoted 7 lines

?endif

(quoted diff) +0 -0
@@ -42,3 +42,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) ?+=

mainstone-wm97xx.o ?obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) ? ?+= zylonite-wm97xx.o ?obj-$(CONFIG_TOUCHSCREEN_W90X900) ? ?+= w90p910_ts.o ?obj-$(CONFIG_TOUCHSCREEN_PCAP) ? ? ? ? ? ? ? += pcap_ts.o +obj-$(CONFIG_TOUCHSCREEN_88PM860X) ? += 88pm860x-ts.o

Would appreciate if you arrange makefile alphabetically.

Quoted 5 lines

Thanks.

--
Dmitry

Up to now, I don't support module yet. When each component of this PMIC is ready, I'll enable module.

Thanks
Haojian

#4 lore raw

PATCH 9/10 input: enable touch on 88pm860x

Quoted 4 lines · Haojian Zhuang

Up to now, I don't support module yet. When each component of this PMIC is ready, I'll enable module.

I would do it rather sooner than later - then you'd notice that you are not freeing IRQ in pm860x_touch_remove() when you'd try to reload your module.

Quoted 9 lines
(quoted diff) +9 -0
+
+static int __devexit pm860x_touch_remove(struct platform_device *pdev)
+{
+	struct pm860x_touch *touch = platform_get_drvdata(pdev);
+
+	input_unregister_device(touch->idev);
+	return 0;
+}
+
Signature · 1 line
Dmitry
#5 lore raw

PATCH 9/10 input: enable touch on 88pm860x

Quoted 10 lines · Dmitry Torokhov
Quoted 4 lines · Haojian Zhuang

Up to now, I don't support module yet. When each component of this PMIC is ready, I'll enable module.

I would do it rather sooner than later - then you'd notice that you are not freeing IRQ in pm860x_touch_remove() when you'd try to reload your module.

Quoted 13 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+
+static int __devexit pm860x_touch_remove(struct platform_device *pdev)
+{
+ ? ? struct pm860x_touch *touch = platform_get_drvdata(pdev);
+
+ ? ? input_unregister_device(touch->idev);
+ ? ? return 0;
+}
+

--
Dmitry

updated with module supported.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-input-enable-touch-on-88pm860x.patch
Type: text/x-patch
Size: 8700 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20091119/f62f38d6/attachment-0001.bin>

#6 lore raw

PATCH 9/10 input: enable touch on 88pm860x

Hi Haojian,

Review

Quoted 5 lines · Haojian Zhuang
(quoted diff) +5 -0
+
+static int __devexit pm860x_touch_remove(struct platform_device *pdev)
+{
+	struct pm860x_touch *touch = platform_get_drvdata(pdev);
+

"pm860x_free_irq(chip, irq);" is still missing here.

Quoted 4 lines
(quoted diff) +4 -0
+	input_unregister_device(touch->idev);
+	return 0;
+}
+

Review

Quoted 10 lines
(quoted diff) +7 -0
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called pcap_ts.
+
+config TOUCHSCREEN_88PM860X
+	tristate "Marvell 88PM860x touchscreen"
+	depends on MFD_88PM860X
+	help
+	  Say Y here if you have a 88PM860x PMIC and want to enable
+	  support for the built-in touchscreen.

"To compile this driver as a module..."

Thanks!

Other than that:

Signature · 1 line
Dmitry
#7 lore raw

PATCH 9/10 input: enable touch on 88pm860x

Quoted 28 lines · Dmitry Torokhov

Hi Haojian,

Review

Quoted 5 lines · Haojian Zhuang
(quoted diff) +5 -0
+
+static int __devexit pm860x_touch_remove(struct platform_device *pdev)
+{
+ ? ? struct pm860x_touch *touch = platform_get_drvdata(pdev);
+

"pm860x_free_irq(chip, irq);" is still missing here.

Quoted 7 lines

+ ? ? input_unregister_device(touch->idev);
+ ? ? return 0;

(quoted diff) +2 -0
+}
+

? ? ? ? To compile this driver as a module, choose M here: the ? ? ? ? module will be called pcap_ts.

Review

Quoted 7 lines
(quoted diff) +7 -0
+
+config TOUCHSCREEN_88PM860X
+ ? ? tristate "Marvell 88PM860x touchscreen"
+ ? ? depends on MFD_88PM860X
+ ? ? help
+ ? ? ? Say Y here if you have a 88PM860x PMIC and want to enable
+ ? ? ? support for the built-in touchscreen.

"To compile this driver as a module..."

Quoted 9 lines

Thanks!

Other than that:

? ? ? ?Acked-by: Dmitry Torokhov <[email protected]>

--
Dmitry

Fixed. Actually it could be built as module already. Now append more comments on it.

Thanks
Haojian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-input-enable-touch-on-88pm860x.patch
Type: text/x-patch
Size: 8855 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20091120/b99dd893/attachment.bin>