linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nick Dyer <nick.dyer@itdev.co.uk>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Daniel Kurtz <djkurtz@chromium.org>,
	Henrik Rydberg <rydberg@euromail.se>,
	Joonyoung Shim <jy0922.shim@samsung.com>,
	Alan.Bowens@atmel.com, linux-input@vger.kernel.org,
	linux-kernel@vger.kernel.org, pmeerw@pmeerw.net,
	bleung@chromium.org, olofj@chromium.org
Cc: Nick Dyer <nick.dyer@itdev.co.uk>
Subject: [PATCH 26/40] Input: atmel_mxt_ts - Implement T63 Active Stylus support
Date: Fri, 22 Feb 2013 17:58:13 +0000	[thread overview]
Message-ID: <1361555907-19840-27-git-send-email-nick.dyer@itdev.co.uk> (raw)
In-Reply-To: <1361555907-19840-1-git-send-email-nick.dyer@itdev.co.uk>

Signed-off-by: Nick Dyer <nick.dyer@itdev.co.uk>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |   91 +++++++++++++++++++++++++++++-
 1 file changed, 90 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index b0dcae4..3aac912 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -76,6 +76,7 @@
 #define MXT_SPT_MESSAGECOUNT_T44	44
 #define MXT_SPT_CTECONFIG_T46		46
 #define MXT_SPT_NOISESUPPRESSION_T48	48
+#define MXT_PROCI_ACTIVE_STYLUS_T63	63
 
 /* MXT_GEN_MESSAGE_T5 object */
 #define MXT_RPTID_NOMSG		0xff
@@ -188,6 +189,19 @@ struct t9_range {
 /* Define for MXT_PROCI_TOUCHSUPPRESSION_T42 */
 #define MXT_T42_MSG_TCHSUP	(1 << 0)
 
+/* T63 Stylus */
+#define MXT_STYLUS_PRESS	(1 << 0)
+#define MXT_STYLUS_RELEASE	(1 << 1)
+#define MXT_STYLUS_MOVE		(1 << 2)
+#define MXT_STYLUS_SUPPRESS	(1 << 3)
+
+#define MXT_STYLUS_DETECT	(1 << 4)
+#define MXT_STYLUS_TIP		(1 << 5)
+#define MXT_STYLUS_ERASER	(1 << 6)
+#define MXT_STYLUS_BARREL	(1 << 7)
+
+#define MXT_STYLUS_PRESSURE_MASK	0x3F
+
 /* Delay times */
 #define MXT_BACKUP_TIME		25	/* msec */
 #define MXT_RESET_TIME		200	/* msec */
@@ -260,6 +274,7 @@ struct mxt_data {
 	bool update_input;
 	u8 last_message_count;
 	u8 num_touchids;
+	u8 num_stylusids;
 
 	/* Cached parameters from object table */
 	u16 T5_address;
@@ -273,6 +288,8 @@ struct mxt_data {
 	u8 T42_reportid_max;
 	u16 T44_address;
 	u8 T48_reportid;
+	u8 T63_reportid_min;
+	u8 T63_reportid_max;
 };
 
 /* I2C slave address pairs */
@@ -727,6 +744,60 @@ static int mxt_proc_t48_messages(struct mxt_data *data, u8 *msg)
 	return 0;
 }
 
+static void mxt_proc_t63_messages(struct mxt_data *data, u8 *msg)
+{
+	struct device *dev = &data->client->dev;
+	struct input_dev *input_dev = data->input_dev;
+	u8 id;
+	u16 x, y;
+	u8 pressure;
+
+	if (!input_dev)
+		return;
+
+	/* stylus slots come after touch slots */
+	id = data->num_touchids + (msg[0] - data->T63_reportid_min);
+
+	if (id < 0 || id > (data->num_touchids + data->num_stylusids)) {
+		dev_err(dev, "invalid stylus id %d, max slot is %d\n",
+			id, data->num_stylusids);
+		return;
+	}
+
+	x = msg[3] | (msg[4] << 8);
+	y = msg[5] | (msg[6] << 8);
+	pressure = msg[7] & MXT_STYLUS_PRESSURE_MASK;
+
+	dev_dbg(dev,
+		"[%d] %c%c%c%c x: %d y: %d pressure: %d stylus:%c%c%c%c\n",
+		id,
+		(msg[1] & MXT_STYLUS_SUPPRESS) ? 'S' : '.',
+		(msg[1] & MXT_STYLUS_MOVE)     ? 'M' : '.',
+		(msg[1] & MXT_STYLUS_RELEASE)  ? 'R' : '.',
+		(msg[1] & MXT_STYLUS_PRESS)    ? 'P' : '.',
+		x, y, pressure,
+		(msg[2] & MXT_STYLUS_BARREL) ? 'B' : '.',
+		(msg[2] & MXT_STYLUS_ERASER) ? 'E' : '.',
+		(msg[2] & MXT_STYLUS_TIP)    ? 'T' : '.',
+		(msg[2] & MXT_STYLUS_DETECT) ? 'D' : '.');
+
+	input_mt_slot(input_dev, id);
+
+	if (msg[2] & MXT_STYLUS_DETECT) {
+		input_mt_report_slot_state(input_dev, MT_TOOL_PEN, 1);
+		input_report_abs(input_dev, ABS_MT_POSITION_X, x);
+		input_report_abs(input_dev, ABS_MT_POSITION_Y, y);
+		input_report_abs(input_dev, ABS_MT_PRESSURE, pressure);
+	} else {
+		input_mt_report_slot_state(input_dev, MT_TOOL_PEN, 0);
+	}
+
+	input_report_key(input_dev, BTN_STYLUS, (msg[2] & MXT_STYLUS_ERASER));
+	input_report_key(input_dev, BTN_STYLUS2, (msg[2] & MXT_STYLUS_BARREL));
+
+	mxt_input_sync(input_dev);
+}
+
 static int mxt_proc_message(struct mxt_data *data, u8 *message)
 {
 	u8 report_id = message[0];
@@ -742,6 +813,10 @@ static int mxt_proc_message(struct mxt_data *data, u8 *message)
 	    && report_id <= data->T9_reportid_max) {
 		mxt_proc_t9_message(data, message);
 		handled = true;
+	} else if (report_id >= data->T63_reportid_min
+		   && report_id <= data->T63_reportid_max) {
+		mxt_proc_t63_messages(data, message);
+		handled = true;
 	} else if (report_id >= data->T42_reportid_min
 		   && report_id <= data->T42_reportid_max) {
 		mxt_proc_t42_messages(data, message);
@@ -1413,6 +1488,12 @@ static int mxt_get_object_table(struct mxt_data *data)
 		case MXT_SPT_NOISESUPPRESSION_T48:
 			data->T48_reportid = min_id;
 			break;
+		case MXT_PROCI_ACTIVE_STYLUS_T63:
+			data->T63_reportid_min = min_id;
+			data->T63_reportid_max = max_id;
+			data->num_stylusids =
+				object->num_report_ids * OBP_INSTANCES(object);
+			break;
 		}
 
 		end_address = object->start_address
@@ -1950,7 +2031,7 @@ static int mxt_initialize_t9_input_device(struct mxt_data *data)
 			     0, 255, 0, 0);
 
 	/* For multi touch */
-	num_mt_slots = data->T9_reportid_max - data->T9_reportid_min + 1;
+	num_mt_slots = data->num_touchids + data->num_stylusids;
 	error = input_mt_init_slots(input_dev, num_mt_slots, 0);
 	if (error)
 		goto err_free_mem;
@@ -1966,6 +2047,14 @@ static int mxt_initialize_t9_input_device(struct mxt_data *data)
 	input_set_abs_params(input_dev, ABS_MT_ORIENTATION,
 			     0, 255, 0, 0);
 
+	/* For T63 active stylus */
+	if (data->T63_reportid_min) {
+		input_set_capability(input_dev, EV_KEY, BTN_STYLUS);
+		input_set_capability(input_dev, EV_KEY, BTN_STYLUS2);
+		input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE,
+			0, MT_TOOL_MAX, 0, 0);
+	}
+
 	input_set_drvdata(input_dev, data);
 
 	error = input_register_device(input_dev);
-- 
1.7.10.4

  parent reply	other threads:[~2013-02-22 17:58 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-22 17:57 Atmel updates to atmel_mxt_ts touch controller driver Nick Dyer
2013-02-22 17:57 ` [PATCH 01/40] Input: atmel_mxt_ts - Make wait-after-reset period compatible with all chips Nick Dyer
2013-02-22 23:20   ` Benson Leung
2013-02-22 17:57 ` [PATCH 02/40] Input: atmel_mxt_ts - add macros for object instances and size Nick Dyer
2013-02-22 17:57 ` [PATCH 03/40] Input: atmel_mxt_ts - Add memory access interface via sysfs Nick Dyer
2013-02-22 17:57 ` [PATCH 04/40] Input: atmel_mxt_ts - Implement debug output for messages Nick Dyer
2013-02-22 17:57 ` [PATCH 05/40] Input: atmel_mxt_ts - Improve error reporting and debug Nick Dyer
2013-02-22 17:57 ` [PATCH 06/40] Input: atmel_mxt_ts - Remove unnecessary platform data Nick Dyer
2013-02-22 17:57 ` [PATCH 07/40] Input: atmel_mxt_ts - Implement CRC check for configuration data Nick Dyer
2013-02-22 17:57 ` [PATCH 08/40] Input: atmel_mxt_ts - Download device config using firmware loader Nick Dyer
2013-02-22 17:57 ` [PATCH 09/40] Input: atmel_mxt_ts - Calculate and check CRC in config file Nick Dyer
2013-02-22 17:57 ` [PATCH 10/40] Input: atmel_mxt_ts - Improve bootloader support Nick Dyer
2013-02-22 17:57 ` [PATCH 11/40] Input: atmel_mxt_ts - Bootloader addresses for mXT1664/mXT1188S Nick Dyer
2013-02-22 19:06   ` Benson Leung
2013-02-22 19:51     ` Nick Dyer
2013-02-22 23:09       ` Benson Leung
2013-02-22 17:57 ` [PATCH 12/40] Input: atmel_mxt_ts - Read screen config from chip Nick Dyer
2013-02-22 17:58 ` [PATCH 13/40] Input: atmel_mxt_ts - Use deep sleep mode when stopped Nick Dyer
2013-02-22 17:58 ` [PATCH 14/40] Input: atmel_mxt_ts - add shutdown function Nick Dyer
2013-02-22 17:58 ` [PATCH 15/40] Input: atmel_mxt_ts - Improve touch reporting for T9 Nick Dyer
2013-02-22 17:58 ` [PATCH 16/40] Input: atmel_mxt_ts - Move input device configuration into separate function Nick Dyer
2013-02-22 17:58 ` [PATCH 17/40] Input: atmel_mxt_ts - Allow input device name to be configured from platform data Nick Dyer
2013-02-22 17:58 ` [PATCH 18/40] Input: atmel_mxt_ts - Add support for dynamic message size Nick Dyer
2013-02-22 17:58 ` [PATCH 19/40] Input: atmel_mxt_ts - Decode T6 status messages Nick Dyer
2013-02-22 17:58 ` [PATCH 20/40] Input: atmel_mxt_ts - Split interrupt handler into separate functions Nick Dyer
2013-02-22 17:58 ` [PATCH 21/40] Input: atmel_mxt_ts - Implement T44 message handling Nick Dyer
2013-02-22 17:58 ` [PATCH 22/40] Input: atmel_mxt_ts - Output status from T48 Noise Supression Nick Dyer
2013-02-22 17:58 ` [PATCH 23/40] Input: atmel_mxt_ts - Output status from T42 Touch Suppression Nick Dyer
2013-02-22 17:58 ` [PATCH 24/40] Input: atmel_mxt_ts - Implement vector/orientation support Nick Dyer
2013-02-22 17:58 ` [PATCH 25/40] Input: atmel_mxt_ts - implement I2C retries Nick Dyer
2013-02-22 17:58 ` Nick Dyer [this message]
2013-02-22 17:58 ` [PATCH 27/40] Input: atmel_mxt_ts - Add check for incorrect firmware file format Nick Dyer
2013-02-22 17:58 ` [PATCH 28/40] Input: atmel_mxt_ts - Add CHG line handling in bootloader code Nick Dyer
2013-02-22 22:35   ` Benson Leung
2013-02-23  1:45   ` Benson Leung
2013-02-22 17:58 ` [PATCH 29/40] Input: atmel_mxt_ts - Use wait_for_chg in soft_reset Nick Dyer
2013-02-22 17:58 ` [PATCH 30/40] Input: atmel_mxt_ts - recover from bootloader on probe Nick Dyer
2013-02-22 17:58 ` [PATCH 31/40] Input: atmel_mxt_ts - Implement T15 Key Array support Nick Dyer
2013-02-22 17:58 ` [PATCH 32/40] Input: atmel_mxt_ts - remove unused defines Nick Dyer
2013-02-22 17:58 ` [PATCH 33/40] Input: atmel_mxt_ts - Verify Information Block checksum on probe Nick Dyer
2013-02-22 17:58 ` [PATCH 34/40] Input: atmel_mxt_ts - Remove mxt_make_highchg Nick Dyer
2013-02-22 17:58 ` [PATCH 35/40] Input: atmel_mxt_ts - Improve messages relating to info block read Nick Dyer
2013-02-22 17:58 ` [PATCH 36/40] Input: atmel_mxt_ts - Handle reports from T47 Stylus object Nick Dyer
2013-02-22 17:58 ` [PATCH 37/40] Input: atmel_mxt_ts - Release touch state during suspend Nick Dyer
2013-02-22 17:58 ` [PATCH 38/40] Input: atmel_mxt_ts - Initialize power config before and after downloading cfg Nick Dyer
2013-02-22 17:58 ` [PATCH 39/40] Input: atmel_mxt_ts - Add regulator control support Nick Dyer
2013-02-22 17:58 ` [PATCH 40/40] Input: atmel_mxt_ts - Implement support for T100 touch object Nick Dyer
2013-02-22 20:19 ` Atmel updates to atmel_mxt_ts touch controller driver Peter Meerwald
2013-02-22 20:53   ` Nick Dyer
2013-03-29 16:48 ` Henrik Rydberg
2013-04-08 14:36   ` Nick Dyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1361555907-19840-27-git-send-email-nick.dyer@itdev.co.uk \
    --to=nick.dyer@itdev.co.uk \
    --cc=Alan.Bowens@atmel.com \
    --cc=bleung@chromium.org \
    --cc=djkurtz@chromium.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jy0922.shim@samsung.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olofj@chromium.org \
    --cc=pmeerw@pmeerw.net \
    --cc=rydberg@euromail.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).