From patchwork Fri Jun 16 07:28:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13282171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9752EEB64DA for ; Fri, 16 Jun 2023 07:29:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231362AbjFPH3Z (ORCPT ); Fri, 16 Jun 2023 03:29:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245011AbjFPH3S (ORCPT ); Fri, 16 Jun 2023 03:29:18 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2057.outbound.protection.outlook.com [40.107.7.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32EF626A9; Fri, 16 Jun 2023 00:29:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kiNFtqIaNYOlCABg2sKaq4TbAaB9MJqmnZ/vHs2JkuCFd/JkL6lPbstnqfxQOpEzdMaWgVfQFs/+K3No2qCTKQYo9gi/CvD24Tl5takBBPu2S1oQMZ/qofFVTFcaRo9dg6sXXF4J5BffAYDLGRPQGRCquGg4NGJCkf8blk+MVlC9AlJVELFBEJ+t0+G7Z74tTs1uEZqj7MCpvjcIlDRWTzS2xb1ZYoKHnU6eeYGlREWQwyIunrUI/4LTqVX6ySFGK2nuVuDKGu5YtgPnOZNBwMfR4XivniCrVUfMOU3dtewGKv6yyehmGDFtE3sGNZPnB8hFkobZI7+hZxh0MaUONg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=sLgaUQuMEy87mQOE6+9pRSxODWfmtoB2wTXnumPyZpI=; b=ee4A7BHVGXjseLzhd7KzH2vEuSUF4p3hMz2RNh9nGjAZs8vEUCuFgwTmZYQY9IfbPnJkJ86mCVQ1y6bI1PqR04j++ptJHFMZ6ODyoXjx06qsMQZqjz+D6DGcWTIg89hQWaZFpTXTFoVcDrT6CkrxrdE0yE85xUE3N295qsLOc4WaVazOkyNTDACgEHpIQZa6WKy0GJUre5ZVzOw8jRz5/pkEp6JxTn22gUZgsIzKNx1TPRwCsnQ6zc1YVBCuAK4yYskwgyCdXhlpv0X+xgEpt6CfsL3xr+j+PkHf1FaVi6+tgWRx6dkbUeGPfXM/OJXluJlZh7DWyzLkZYIs0eVrIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wolfvision.net; dmarc=pass action=none header.from=wolfvision.net; dkim=pass header.d=wolfvision.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wolfvision.net; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sLgaUQuMEy87mQOE6+9pRSxODWfmtoB2wTXnumPyZpI=; b=J2xSIIzq+gLBreJq7GpbCWQKP3Dre6WP9QEGJk9Xhz5k6Jl+DGtYMYUMEw/baKyHGf4v/Piijn3g35KnkTZhBjp8XNidJ3j/7K+TOMoQzcd/PkW0rxsOF/wMb3kQlfnw7pjQGu04A+LGzpY7P7c44kDLXNwdXJD2wqU3m/k6doU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) by GV1PR08MB9916.eurprd08.prod.outlook.com (2603:10a6:150:a6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37; Fri, 16 Jun 2023 07:29:11 +0000 Received: from VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::bd0e:a139:9e67:b86d]) by VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::bd0e:a139:9e67:b86d%4]) with mapi id 15.20.6477.037; Fri, 16 Jun 2023 07:29:11 +0000 From: Javier Carrasco Date: Fri, 16 Jun 2023 09:28:53 +0200 Subject: [PATCH v3 3/4] Input: st1232 - add overlay touchscreen and buttons handling Message-Id: <20230510-feature-ts_virtobj_patch-v3-3-b4fb7fc4bab7@wolfvision.net> References: <20230510-feature-ts_virtobj_patch-v3-0-b4fb7fc4bab7@wolfvision.net> In-Reply-To: <20230510-feature-ts_virtobj_patch-v3-0-b4fb7fc4bab7@wolfvision.net> To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Henrik Rydberg , Bastian Hecht , Michael Riesch Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, devicetree@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.12.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1686900549; l=6684; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=Ufj+40UV5TZ6PtKmvGP2w2PJ/I7zFECdsQf3vvqBzHU=; b=375jOJh0X/XWT8jYPZJRozUoliXOe5jkfsTwibeMlUaYt9ii4Dw9RajpyCwrhZP/I3PrsITna 8RVEfXMii4kAzI9WpMbz4bnIdd8QxnWhQhuG+AZpwgGH7TZnX3w6zGE X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1PR07CA0197.eurprd07.prod.outlook.com (2603:10a6:802:3f::21) To VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4974:EE_|GV1PR08MB9916:EE_ X-MS-Office365-Filtering-Correlation-Id: a76a3520-f15c-492f-52ac-08db6e3b6085 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YUNPbzUEyYlJ0etxSaHPvjxqH3fYoIO9syALhg9fkpMzP5bOrosyCGooV9escL8prwIB/DdZGZpTtMMb8yjCPiFdupq3gznd737ZORhQU4VzfaYShqu6YU37FvJnw2q9oIq+w/yfP2MYEczXSztEYaGLa3wAGYvOO7TN12zeT3Fv4X1p9LxKE/925ZVar3I/FdouJJWwn8yodPAERcHsGeB6so6ASp7fLvpQ5qWwo0GaplucQe9G95IBMVMOlxeFDmhr0rvS7oND1zKBK73PqznIFJffW8fbpYwBsvRstpxMdvvmgWvO0y6MmJQsXFnsZj8724UAWEsQxk7o7Fo3pKhuHYkBWWc8oKabsF28taXxc2oQRe5spHzdaw/5zOte9N3CakviTnFmPFgx9ZLjAZPH3srJR8F9vUcvbo6kOakEe5R29fYEHKJMI45MX/ANii2NgNLZYlPzbdmWDwybuZq39lmXJanex22MZe+SapX6zvmuHrJPe05tQqwU5SNpFuNcgt8gBXgYKi/KhO5dycYf8lHYV7Q5TxCJ7IP87yZi1Ha56inIS5bWrXY9bW587O3EJrvVeSze/ctl2lhQXiCH1NEPlov4Zh/bjjgmb9lFO3ImLHyT2y3e9y7OyqxQ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VE1PR08MB4974.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(396003)(366004)(39850400004)(346002)(451199021)(36756003)(86362001)(2906002)(44832011)(83380400001)(6486002)(6666004)(186003)(52116002)(107886003)(6512007)(6506007)(26005)(6636002)(66476007)(110136005)(316002)(41300700001)(38100700002)(4326008)(66556008)(2616005)(38350700002)(66946007)(5660300002)(478600001)(8676002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?6IZ0B+G+jTZa8FcKQ38FgpLq9Ejo?= =?utf-8?q?ms/PxDH0hLAaTEEh9ygz9hiByx9TUHx5PISJpa3JwCnmKdF3iAY/3eGUQgU5XChlR?= =?utf-8?q?dNKWUpfChLi/CH6qL8ZNcB+V9cL07Omr3PLbwj5ln3S4xr4V6IevcsNgC8hjkCfDk?= =?utf-8?q?dfB9kkY/GzpWcmvkxIRKFbgxEiR4SsQGC09HuvGCwYqaE17YS5ydc4wGIYGPK63bW?= =?utf-8?q?0wvOtlni/r+QJp9Ev0wNh2kv4QOiyupKKl94Ydyy9uJy2YJLYr+nhXSHZcO0Vc6oU?= =?utf-8?q?U+D2x2noFlp8McxAUzmuymYymbuJhRMpNVdARCKyVeMi/KGnNEG2XS5xuLHZzb+p9?= =?utf-8?q?B4SlimF7eiIYTYybON9c2sTChoVby/Dv5wPiNoCcyJRIQ9L4cq+LzRLfS0S0PSJhM?= =?utf-8?q?IVzMmBj370L9grhSgb3+zK2fdQfRxs/kHUpHRVZnCY5WfE2nNkjOwrYTmrnWKZi9U?= =?utf-8?q?3N01w02KrqM2wpo3+ia/mSJSV3J2lLVgOINF94lDw/RfcQ4LdSzhaMqsighgYgHym?= =?utf-8?q?Hby1e48vyL9bcJPsz3e0wRt1NfaVaqHS288QuOqoBmUYqkH5d+WQFLPYNTzbj76zR?= =?utf-8?q?sUHB6og82fiP0dPuPkvpBQ/UUe8nwv6y/edyRsAZJ97qO7iBnrQaG5NXJIxrelb8o?= =?utf-8?q?0trg3dXZK/EOKfD6zAdagqQbFQxKZXicAeCs4VqkzCjbbkePmgq1+eSoAs0jmRdzT?= =?utf-8?q?Oq2ECoSLrlhll2Kjh85IvgGojsX9gn/aB2SK45pxLY7IvVySlP67dI5SjxpuEFKsF?= =?utf-8?q?Ix6mx1sckmUKfGVVxQYScFcBrxKFxeQibQRTeDB6o/5PKf4QCufJlZjsmgOON0URz?= =?utf-8?q?SSEZcJtD0346vrkzVwmY/QEJJ7qiP4ruFLJyAInXYrmGzn+pdy3Bjx9namLVke0Gn?= =?utf-8?q?8xA2kihTCRyQHSwXSnSXMQGIgSvQwIB28ySkpE1VbwAe6Sby6qK0y/4lta/o3N5t/?= =?utf-8?q?CXUJ8EqZ1yEdpxRZs1+imxXoTCROTC3kDln1zgsp7RCSNdtQEuiIhYnFqlq3Cjx7b?= =?utf-8?q?bqmXS9c1kSDvcbLISlpyiDkACK5KX1HRaaNVkeuEge/X/VdC0/1RibRVU7M8qkkxg?= =?utf-8?q?nISTvL71mc6RH5WE8fZoLXzRPuaqn+Ur625/Ok45b3U9oLEeW/ViG6jVpitY2y5eV?= =?utf-8?q?JOFsS6lMiAfVMSJVLysivA/0AKsHK0p7SUcf6YFgE5605rSgA7xIfVt12vsJmUkuE?= =?utf-8?q?xkhHFoWldtBvQhD20/9prGUdPw9k5YE3MaNQfaBiAWcklPC/xqTJjzTyQ8p3gCzm3?= =?utf-8?q?1OKC7w2jgB0q/yzX3CyipJvl5mvwBbZw2bcjc31QPsutUJSgfEzLLQhGq+YAGjk2i?= =?utf-8?q?VOFXhrXuQ5UIs9R/zLmhFoU1W3ozpTnwpwNCoShfKFqQFSIBAA+/jPpbyLs4oVUIk?= =?utf-8?q?THYD2/wH4XsJCIKIUvmbwzBcyQE6K7aXEzWPiwyKgbDL+9XrsP1SyVL2sutzLvWWd?= =?utf-8?q?gaLMC5L40ubwnoItHQgdxnYgwlyZxQlf/JwlNL3WSCiJVvE+YbE/sEW5TJFAE7Ycy?= =?utf-8?q?7m1qV5rVBkxpCwQjaMi22MFKEfrdWEYrKQ=3D=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: a76a3520-f15c-492f-52ac-08db6e3b6085 X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4974.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2023 07:29:10.5897 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: e94ec9da-9183-471e-83b3-51baa8eb804f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: t6+21fR4sRzRrJDkYi+NIwWOR9MZaOK2Od8oEk3t894xu3pgdCL+rO5IWYCqL5AeWKD8pSGKKylEgsJUYcXeGopC1nGxUQ9XuKOwAQvpvbM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB9916 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Use ts-overlay to support overlay objects such as buttons and resized frames defined in the device tree. If a overlay-touchscreen is provided, ignore touch events outside of the area defined by its properties. Otherwise, transform the event coordinates to the overlay-touchscreen x and y-axis if required. If buttons are provided, register an additional device to report key events separately. A key event will be generated if the coordinates of a touch event are within the area defined by the button properties. Signed-off-by: Javier Carrasco --- drivers/input/touchscreen/Kconfig | 1 + drivers/input/touchscreen/st1232.c | 87 ++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 8382a4d68326..202e559371e8 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1215,6 +1215,7 @@ config TOUCHSCREEN_SIS_I2C config TOUCHSCREEN_ST1232 tristate "Sitronix ST1232 or ST1633 touchscreen controllers" depends on I2C + select TOUCHSCREEN_TS_OVERLAY help Say Y here if you want to support the Sitronix ST1232 or ST1633 touchscreen controller. diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index f49566dc96f8..7d8a69e4831b 100644 --- a/drivers/input/touchscreen/st1232.c +++ b/drivers/input/touchscreen/st1232.c @@ -22,6 +22,7 @@ #include #include #include +#include #define ST1232_TS_NAME "st1232-ts" #define ST1633_TS_NAME "st1633-ts" @@ -56,6 +57,8 @@ struct st1232_ts_data { struct touchscreen_properties prop; struct dev_pm_qos_request low_latency_req; struct gpio_desc *reset_gpio; + struct input_dev *overlay_keypad; + struct ts_overlay_map *map; const struct st_chip_info *chip_info; int read_buf_len; u8 *read_buf; @@ -129,10 +132,12 @@ static int st1232_ts_read_resolution(struct st1232_ts_data *ts, u16 *max_x, static int st1232_ts_parse_and_report(struct st1232_ts_data *ts) { - struct input_dev *input = ts->input_dev; + struct input_dev *tscreen = ts->input_dev; + __maybe_unused struct input_dev *keypad = ts->overlay_keypad; struct input_mt_pos pos[ST_TS_MAX_FINGERS]; u8 z[ST_TS_MAX_FINGERS]; int slots[ST_TS_MAX_FINGERS]; + __maybe_unused bool button_pressed[ST_TS_MAX_FINGERS]; int n_contacts = 0; int i; @@ -143,6 +148,15 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts) unsigned int x = ((buf[0] & 0x70) << 4) | buf[1]; unsigned int y = ((buf[0] & 0x07) << 8) | buf[2]; + /* forward button presses to the keypad input device */ + if (ts_overlay_is_button_slot(ts->map, i) || + ts_overlay_button_press(ts->map, keypad, x, y, i)) { + button_pressed[i] = true; + continue; + } + /* Ignore events out of the overlay screen if defined */ + if (!ts_overlay_mt_on_touchscreen(ts->map, &x, &y)) + continue; touchscreen_set_mt_pos(&pos[n_contacts], &ts->prop, x, y); @@ -154,18 +168,25 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts) } } - input_mt_assign_slots(input, slots, pos, n_contacts, 0); + input_mt_assign_slots(tscreen, slots, pos, n_contacts, 0); for (i = 0; i < n_contacts; i++) { - input_mt_slot(input, slots[i]); - input_mt_report_slot_state(input, MT_TOOL_FINGER, true); - input_report_abs(input, ABS_MT_POSITION_X, pos[i].x); - input_report_abs(input, ABS_MT_POSITION_Y, pos[i].y); + input_mt_slot(tscreen, slots[i]); + input_mt_report_slot_state(tscreen, MT_TOOL_FINGER, true); + input_report_abs(tscreen, ABS_MT_POSITION_X, pos[i].x); + input_report_abs(tscreen, ABS_MT_POSITION_Y, pos[i].y); if (ts->chip_info->have_z) - input_report_abs(input, ABS_MT_TOUCH_MAJOR, z[i]); + input_report_abs(tscreen, ABS_MT_TOUCH_MAJOR, z[i]); + } + input_mt_sync_frame(tscreen); + input_sync(tscreen); + + if (ts_overlay_mapped_buttons(ts->map)) { + for (i = 0; i < ts->chip_info->max_fingers; i++) + if (ts_overlay_is_button_slot(ts->map, i) && + !button_pressed[i]) + ts_overlay_button_release(ts->map, keypad, i); + input_sync(keypad); } - - input_mt_sync_frame(input); - input_sync(input); return n_contacts; } @@ -226,6 +247,7 @@ static int st1232_ts_probe(struct i2c_client *client) const struct st_chip_info *match; struct st1232_ts_data *ts; struct input_dev *input_dev; + struct input_dev __maybe_unused *overlay_keypad; u16 max_x, max_y; int error; @@ -292,18 +314,28 @@ static int st1232_ts_probe(struct i2c_client *client) if (error) return error; - /* Read resolution from the chip */ - error = st1232_ts_read_resolution(ts, &max_x, &max_y); - if (error) { - dev_err(&client->dev, - "Failed to read resolution: %d\n", error); - return error; - } - if (ts->chip_info->have_z) input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, ts->chip_info->max_area, 0, 0); + /* map overlay objects if defined in the device tree */ + ts->map = ts_overlay_map_objects(&ts->client->dev, ts->input_dev); + if (IS_ERR(ts->map)) + return PTR_ERR(ts->map); + + if (ts_overlay_mapped_touchscreen(ts->map)) { + /* Read resolution from the overlay touchscreen if defined*/ + ts_overlay_get_touchscreen_abs(ts->map, &max_x, &max_y); + } else { + /* Read resolution from the chip */ + error = st1232_ts_read_resolution(ts, &max_x, &max_y); + if (error) { + dev_err(&client->dev, + "Failed to read resolution: %d\n", error); + return error; + } + } + input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0); input_set_abs_params(input_dev, ABS_MT_POSITION_Y, @@ -335,6 +367,25 @@ static int st1232_ts_probe(struct i2c_client *client) return error; } + /* Register keypad input device if overlay buttons were defined */ + if (ts_overlay_mapped_buttons(ts->map)) { + overlay_keypad = devm_input_allocate_device(&client->dev); + if (!overlay_keypad) + return -ENOMEM; + + ts->overlay_keypad = overlay_keypad; + overlay_keypad->name = "st1232-keypad"; + overlay_keypad->id.bustype = BUS_I2C; + ts_overlay_set_button_caps(ts->map, overlay_keypad); + error = input_register_device(ts->overlay_keypad); + if (error) { + dev_err(&client->dev, + "Unable to register %s input device\n", + overlay_keypad->name); + return error; + } + } + i2c_set_clientdata(client, ts); return 0;