From patchwork Wed Mar 6 07:41:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benson Leung X-Patchwork-Id: 2223571 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 8524A4020C for ; Wed, 6 Mar 2013 07:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754576Ab3CFHmJ (ORCPT ); Wed, 6 Mar 2013 02:42:09 -0500 Received: from mail-ia0-f178.google.com ([209.85.210.178]:37958 "EHLO mail-ia0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754548Ab3CFHmE (ORCPT ); Wed, 6 Mar 2013 02:42:04 -0500 Received: by mail-ia0-f178.google.com with SMTP id o25so890789iad.23 for ; Tue, 05 Mar 2013 23:42:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=41bLQiRuEdyucCbYZ2btFac9pqKG19VIcIqulRHUKR8=; b=c5uoUNFtfYmZdif8ZCxQlMJiVXvbGwcZzUKHHMA17PM7OstFgHgOpSexfG1gRmYku0 Ryt54ZuYEtAjUA96YkULJ2JnzB23X7gC1JHKIVn+e31UscIRm/6U7/fBmxRy4rIUz8uD 109kiDJP6WCOH9kedkiGeYu8vxNp0wIMnP0uQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=41bLQiRuEdyucCbYZ2btFac9pqKG19VIcIqulRHUKR8=; b=BYZthPC4Y0NFZzjCQGtjE80O5gAsIXsHR4ueTOip3cbHj0sQnKj52GDXlAQoOQUaMc GX7oVm5lsB2DFpBOp+gP/7iy+jhd8CpHlSRQCAj6+qJz/9XJFbSVW9osP9419ickamhC VbNbKqI1tX3G+q0Yldzqi3k980bvPj2jOa9hg2ILIFsqv6JwVv9ncbo5yDukFOhy4hjK LYYzUYxYtddUNDe1USK3DY3uJ1amXk0mHNwZ6KW32LB3sNOtDg6QiKhY5z5DPzRFJAzP QsK/Wduac09Xf2rxHiQHxnX0HhB6HyIhHJ4XmKVTI6AeY8P5t52II5ZNIoTDZy5JBgeT xzxQ== X-Received: by 10.50.6.202 with SMTP id d10mr9316703iga.28.1362555724243; Tue, 05 Mar 2013 23:42:04 -0800 (PST) Received: from laughingman.mtv.corp.google.com (laughingman.mtv.corp.google.com [172.22.73.99]) by mx.google.com with ESMTPS id g6sm19638174ign.4.2013.03.05.23.42.02 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Mar 2013 23:42:03 -0800 (PST) From: Benson Leung To: olofj@chromium.org, miletus@chromium.org, dmitry.torokhov@gmail.com, matthew.garrett@nebula.com, rydberg@euromail.se, djkurtz@chromium.org, jy0922.shim@samsung.com, wfp5p@virginia.edu, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org Cc: bleung@chromium.org, Nick Dyer Subject: [PATCH v2 1/2] Input: atmel_mxt_ts - add device id for touchpad variant Date: Tue, 5 Mar 2013 23:41:46 -0800 Message-Id: <1362555707-24654-2-git-send-email-bleung@chromium.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1362555707-24654-1-git-send-email-bleung@chromium.org> References: <1362187254-9227-1-git-send-email-bleung@chromium.org> <1362555707-24654-1-git-send-email-bleung@chromium.org> X-Gm-Message-State: ALoCoQlu1mwn4z8H1PUi2c7mDkEbSjcDBrFC2MrUDIsUYBfDelYqkWF38Lt3k2/nRYoJ6IbimRGE Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Daniel Kurtz This same driver can be used by atmel based touchscreens and touchpads (buttonpads) by instantiating the i2c device as a "atmel_mxt_tp". This will cause the driver to perform some touchpad specific initializations, such as: * register input device name "Atmel maXTouch Touchpad" instead of Touchscreen. * register BTN_LEFT & BTN_TOOL_* event types. * register axis resolution (as a fixed constant, for now) * register BUTTONPAD property * process GPIO buttons using reportid T19 For now, the left mouse button is mapped to GPIO3. Going forward, platform data should specify the configuration of the buttons. They can be configured via a future platform data change to specify optional middle and right buttons, as well as other possible uses for the GPIO object T19. Signed-off-by: Daniel Kurtz Signed-off-by: Benson Leung Signed-off-by: Nick Dyer Tested-by: Olof Johansson --- v2: zero reportid in mxt_object_table_free(), Thanks nick.dyer@itdev.co.uk v1: Initial --- drivers/input/touchscreen/atmel_mxt_ts.c | 57 ++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index d04f810..3611a26 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -181,6 +181,12 @@ #define MXT_FWRESET_TIME 175 /* msec */ +/* MXT_SPT_GPIOPWM_T19 field */ +#define MXT_GPIO0_MASK 0x04 +#define MXT_GPIO1_MASK 0x08 +#define MXT_GPIO2_MASK 0x10 +#define MXT_GPIO3_MASK 0x20 + /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa #define MXT_UNLOCK_CMD_LSB 0xdc @@ -212,6 +218,8 @@ /* Touchscreen absolute values */ #define MXT_MAX_AREA 0xff +#define MXT_PIXELS_PER_MM 20 + struct mxt_info { u8 family_id; u8 variant_id; @@ -243,6 +251,8 @@ struct mxt_data { const struct mxt_platform_data *pdata; struct mxt_object *object_table; struct mxt_info info; + bool is_tp; + unsigned int irq; unsigned int max_x; unsigned int max_y; @@ -251,6 +261,7 @@ struct mxt_data { u8 T6_reportid; u8 T9_reportid_min; u8 T9_reportid_max; + u8 T19_reportid; }; static bool mxt_object_readable(unsigned int type) @@ -502,6 +513,18 @@ static int mxt_write_object(struct mxt_data *data, return mxt_write_reg(data->client, reg + offset, val); } +static void mxt_input_button(struct mxt_data *data, struct mxt_message *message) +{ + struct device *dev = &data->client->dev; + struct input_dev *input = data->input_dev; + bool button; + + /* Active-low switch */ + button = !(message->message[0] & MXT_GPIO3_MASK); + input_report_key(input, BTN_LEFT, button); + dev_dbg(dev, "Button state: %d\n", button); +} + static void mxt_input_touchevent(struct mxt_data *data, struct mxt_message *message, int id) { @@ -585,6 +608,9 @@ static irqreturn_t mxt_interrupt(int irq, void *dev_id) int id = reportid - data->T9_reportid_min; mxt_input_touchevent(data, &message, id); update_input = true; + } else if (message.reportid == data->T19_reportid) { + mxt_input_button(data, &message); + update_input = true; } else { mxt_dump_message(dev, &message); } @@ -764,6 +790,9 @@ static int mxt_get_object_table(struct mxt_data *data) data->T9_reportid_min = min_id; data->T9_reportid_max = max_id; break; + case MXT_SPT_GPIOPWM_T19: + data->T19_reportid = min_id; + break; } } @@ -777,7 +806,7 @@ static void mxt_free_object_table(struct mxt_data *data) data->T6_reportid = 0; data->T9_reportid_min = 0; data->T9_reportid_max = 0; - + data->T19_reportid = 0; } static int mxt_initialize(struct mxt_data *data) @@ -1115,9 +1144,13 @@ static int mxt_probe(struct i2c_client *client, goto err_free_mem; } - input_dev->name = "Atmel maXTouch Touchscreen"; + data->is_tp = !strcmp(id->name, "atmel_mxt_tp"); + + input_dev->name = (data->is_tp) ? "Atmel maXTouch Touchpad" : + "Atmel maXTouch Touchscreen"; snprintf(data->phys, sizeof(data->phys), "i2c-%u-%04x/input0", client->adapter->nr, client->addr); + input_dev->phys = data->phys; input_dev->id.bustype = BUS_I2C; @@ -1140,6 +1173,25 @@ static int mxt_probe(struct i2c_client *client, __set_bit(EV_KEY, input_dev->evbit); __set_bit(BTN_TOUCH, input_dev->keybit); + if (data->is_tp) { + __set_bit(INPUT_PROP_POINTER, input_dev->propbit); + __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit); + + __set_bit(BTN_LEFT, input_dev->keybit); + __set_bit(BTN_TOOL_FINGER, input_dev->keybit); + __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit); + __set_bit(BTN_TOOL_TRIPLETAP, input_dev->keybit); + __set_bit(BTN_TOOL_QUADTAP, input_dev->keybit); + __set_bit(BTN_TOOL_QUINTTAP, input_dev->keybit); + + input_abs_set_res(input_dev, ABS_X, MXT_PIXELS_PER_MM); + input_abs_set_res(input_dev, ABS_Y, MXT_PIXELS_PER_MM); + input_abs_set_res(input_dev, ABS_MT_POSITION_X, + MXT_PIXELS_PER_MM); + input_abs_set_res(input_dev, ABS_MT_POSITION_Y, + MXT_PIXELS_PER_MM); + } + /* For single touch */ input_set_abs_params(input_dev, ABS_X, 0, data->max_x, 0, 0); @@ -1258,6 +1310,7 @@ static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume); static const struct i2c_device_id mxt_id[] = { { "qt602240_ts", 0 }, { "atmel_mxt_ts", 0 }, + { "atmel_mxt_tp", 0 }, { "mXT224", 0 }, { } };