From patchwork Tue Oct 17 11:00:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 734611 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D7F9B41753 for ; Tue, 17 Oct 2023 11:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="nBYptv/I" Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2047.outbound.protection.outlook.com [40.107.249.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEEE7EA; Tue, 17 Oct 2023 04:00:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sy1olJNOhmDHRBOhus44YvgfCURDJ8BkBmXgF5EyUwn05arVsyDHwZVQf5qTGcfNveYe3dWV9BcjT5SWFufnyVGL58sv/jDcy2vaoDSR36rlB56iGmxXiaMDhSgEc6kwfDrD7CprQ4sfv99Map6oOUFe8W2stgP6ptHMKzHFxr/aUAZ0CuW0Osv0cIVzpN/2ezFuqwNhWcWuzAfIypkPgXCa9Cft+xOLd8FFdoVqFbBWLsslqUY8v5JgTvMuho6LGAe+X+98ZV4FzACbg1yHB3evvED8ksIB5MSk86oJAxYhmQQZbBwsqTw4PZ3rElE9RJ6nC6aXDh+396cUq/Xezg== 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=OJEi3vJTduqpwezb9xJhU4ifPF+ITuUK8LQovSBDtjI=; b=h6zi0FlKCBmQpU1KBuQ6OiIqS7JIINA3sT4Os/aYdv1Nh+E9ckAcclvUgYhgCHlZj3uAkLc1PwFs91mKSaxA/Cf3iPjFLhvgUSgfYa6qSd0I2myjZhowaOLzfQptF5sHn4ZFVaSvY69rWd3rg8LJh873CclEG+MBylyxV6duh0KW8ak2hUvjATA/QwA8aA56oviG8C5f9Qb+DILac/B2Sj8xZJDZI8iL7AgJoM5qaadKdF8MXcg3XGhTU35bRsPwVvtQr8FBa1nxXP6KCrAccKxvP4r4wjwpPZ/YFzAdYhDRo/clDpxUSqc24zYcxHdeSfSOItg9VcvK16euokf5NA== 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=OJEi3vJTduqpwezb9xJhU4ifPF+ITuUK8LQovSBDtjI=; b=nBYptv/IjX+ZInccxbjyVS1XcywJEfJSC79fxvlYFQfl+J97PCtKrT7VmqPGmB1+E8SA0vEZHsbXfJpZEMTBm+gTxuLXKwvZLopsLoDMsCDBZWO+urA3i91eaR/jIjZ6LSQgLyVHW2QMEVlGBrDRVlNe9U2A1/XURr1toFSbuGA= 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 AS8PR08MB6295.eurprd08.prod.outlook.com (2603:10a6:20b:295::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Tue, 17 Oct 2023 11:00:14 +0000 Received: from VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::bc92:216b:11ed:db63]) by VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::bc92:216b:11ed:db63%6]) with mapi id 15.20.6886.034; Tue, 17 Oct 2023 11:00:14 +0000 From: Javier Carrasco Date: Tue, 17 Oct 2023 13:00:07 +0200 Subject: [PATCH v5 1/4] Input: touch-overlay - Add touchscreen overlay object handling Message-Id: <20230510-feature-ts_virtobj_patch-v5-1-ff6b5c4db693@wolfvision.net> References: <20230510-feature-ts_virtobj_patch-v5-0-ff6b5c4db693@wolfvision.net> In-Reply-To: <20230510-feature-ts_virtobj_patch-v5-0-ff6b5c4db693@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=1697540413; l=13918; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=qqwR/kVL/sYBH0UecdndEJ2NdLb3YcmcKBDR3n9upRE=; b=x37HELZ1xdHJkxwJd6Atm9hDaBs3yJWMpyRpcia9Yz1XStauFQqcc0A1QrqNeg1he36APZDg/ ZyVFcebCV1nAIlKguXz7Z7oxcCPgR1OhsK6ovF8DPCQbhhlh8Qv75Nl X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1PR07CA0250.eurprd07.prod.outlook.com (2603:10a6:803:b4::17) To VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4974:EE_|AS8PR08MB6295:EE_ X-MS-Office365-Filtering-Correlation-Id: 5ce8f732-03d9-45e6-e69a-08dbcf003d81 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NJdf0Hkaftpq/D3rwJLoFPwnLFyQY6koaFvJPYdLXv8G2k7RpaQdfnOiENzn7A2Cxy38GkEoG601+UUM660pzQa7vBEp+90101jnFMfNmKyL1BUBLCKu46LezitrO5/lk1pCZspk77ooSXMU2uWdy3BC6EFrleSE41Y5/sik4paY/Di46D264VKrbX9eDAqLT8Ak3OxsUvz3FnwUkn6hQtF8hTLIL8zb8ICN+KlrXhexZYl3zzWhdD3mVDdTvb+tulx169zyP0i9VjSpqfzhbNvb5yFf9Ow0XwaiKolGM9ZPlNj030KwJM8lAqd+G/vOVwe4C7UU6ZAgTIuFZ7qoxvPCakkFoy/27JxtnlX4hLxfh3QAxe/BK0Gzpvi7Owy5mkBZHSdwKi1SOWmha+tcFlUtt4jBIJQUbZUv46aO6VAFLRXcl71pjE00QzjLDjb6gsf6pluWx4A5Y4WKsn3WkkJKX8MQjOrwr4+4QFUxbPD3hCgw4yeNsY2HEGuJAkG5Xol7Q9wHjiJSVb84c0K+7Pkm/2ny1rDrqXVl9M0v1wu6BdsiEV9LPNm1sAc34WRwzatJT+J9RrAgKMMUdI8kbQrbIqQ8tpVo14B5gm5ZfbE= 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:(13230031)(136003)(346002)(376002)(39840400004)(396003)(366004)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(107886003)(478600001)(38100700002)(52116002)(6506007)(2616005)(6486002)(38350700005)(83380400001)(26005)(966005)(6512007)(6666004)(41300700001)(44832011)(5660300002)(4326008)(8936002)(8676002)(316002)(66946007)(30864003)(86362001)(110136005)(2906002)(66556008)(66476007)(6636002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?B/GSu/CJ3RdWBGm2+foWmZAa+HKs?= =?utf-8?q?zFxFZuu1ilXtcqYlXMgbw1x7EStQWAknDhpzBoApuGqNzjBlZbKH4BWff3W6vZ5zy?= =?utf-8?q?p+PflYoYHiVkEHYDTUDl1NxmZmgqgirtIddj6LbQArMA0RBfM5qnnqDt2SjrS3w4x?= =?utf-8?q?JbvQflO3BY4V2toY++FbJGxsGwubEs5w+ore/r3IF+0EMW7yOkcghFr5sQ7k4ckLh?= =?utf-8?q?Gr2TewfZusxZP9winHcpOMzaN9X/zI0ShkS12mAPOPUSXYQBq7BEcqXpv/uOt/4rd?= =?utf-8?q?fSdX1uhnb6KGdN482wR5kEnCWlzqlGf97N5tUVgSJdSce8YL1ICMX/l587uR+Fl06?= =?utf-8?q?fm0PtenUDCNC9YqOtCW+98dFojHkXgS3Sx6B19a5LqDWKqkA2Cnz18TtP9IcqXERG?= =?utf-8?q?nr45WIFPusZCB/rtLOJyMWNF3gyDqi0KgdJTS55Um7OJvHLYAHAsQv4ApLbPizsMm?= =?utf-8?q?5IhMWG/BOBCljUHdU/JzIdGX3ul2ikPIYNRvCxveF9WTuLbXvUBrzfLjpgFwT+ScX?= =?utf-8?q?qG/MIDF6b262rmAuyU6LeAbBLp7Tx2eSTeXQLHnccHvrikaOto1vdL/RsWP8GCVrw?= =?utf-8?q?OjgaGb7c+G2OY6K2p+u72aFyoC25ZNTZjxRXkwlVWAouRP7W9iMmlYfkDsrv5uoeW?= =?utf-8?q?Y1eqjScfcDQTqQbKOQqo4vrwS+c5+wRXvcCVdMMd4tffXWLrxnjwTwvVpc8G7CM3u?= =?utf-8?q?T75vbiRs8fNLm67ECtlq/vjFMHb14vZ3iC7jnj8I7zVvOfw4CpQX7rarj0gvaGscG?= =?utf-8?q?aAUtok6zrhqaL2WKT8G8brVVudDrY3GUXmiI3MgG/nTVjtJUTw/yWTKOsGMVe4eLd?= =?utf-8?q?Qq3SfKbWIKeanORan/mZ0kUmS2FvuNaYDMyOjh6oCOAl8t8M7JcUbgs+u2g27xvts?= =?utf-8?q?jMlRgl21CidxqL5R0WDLVS1poddznZ/nmNk3/w7CF6hdXIpiELsGhF0CuloNng3yi?= =?utf-8?q?yypbWtEXkvZeEFHXf6l1JyzvH7v/jNSXUYkqsWQ+6ia1ek3fcKJyYkOwGT1jQrfHX?= =?utf-8?q?ZWqn6aU1WGtOdhB5EN+r82ySAew9p0YyyTtK+7flWaExUHy/9enCw+BqGpWvGeTT6?= =?utf-8?q?HUCuAcAqV9jQh8uPrI/y/Wdej7DELbeDz9VjpJCYAKeuPCkaJ78RKFPnxiUmTFsr6?= =?utf-8?q?sLyrOk/nWxH7OxzmuodXMw6j4glulosYhf5VDtrvIQyRpRUvu0nfshBh+jemj1Yzo?= =?utf-8?q?jKbeVnluOicwFquNwHRY61XN/oXjObhWXJ40PQeX8UaXIp8afa13Ts7UcuUv4z4y8?= =?utf-8?q?4VINtz1i8ZjBZHKgXBRqOwp4PP2+pUPvfpGHf1Ui8oWR/9g5jcalz4LLB6BdoYdfH?= =?utf-8?q?VPQfrMc53BEFJWm4EjEb276lH0TLe2ev4W7uvtikM3KCWdr+mVJGHOAGRXVQAuwbb?= =?utf-8?q?yQ7Pox2B/GODqnZl/F2l8slqhOUL5B3oFrX+K7rd7mf4UH8m/E3LhyBBuW+aTEwIL?= =?utf-8?q?GqnixRrSBnr2vFUQv3vcRhpflTG/HzoUYWVpBz+5ktOiB2MISqivN59Pt+tmSw39I?= =?utf-8?q?oJeWqpXi+csX689kvBOLdHwevsH64wpIsx/HlXGpyc61jDiNb97RNw8=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 5ce8f732-03d9-45e6-e69a-08dbcf003d81 X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4974.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 11:00:14.3346 (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: sp/yNjIl2+KKHBb0kwFSlZDQSvsSuPeMtRMoDHcdppRPPskU5/LSfUoa5Hn+yGcMvcXvmcWmuQaCPxyBX2cad0kN7H20LbI1CCnvKNoXbS0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6295 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Some touch devices provide mechanical overlays with different objects like buttons or clipped touchscreen surfaces. In order to support these objects, add a series of helper functions to the input subsystem to transform them into overlay objects via device tree nodes. These overlay objects consume the raw touch events and report the expected input events depending on the object properties. Signed-off-by: Javier Carrasco --- MAINTAINERS | 7 + drivers/input/Makefile | 2 +- drivers/input/touch-overlay.c | 399 ++++++++++++++++++++++++++++++++++++ include/linux/input/touch-overlay.h | 34 +++ 4 files changed, 441 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 7a7bd8bd80e9..00c03824c3ac 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21884,6 +21884,13 @@ W: https://github.com/srcres258/linux-doc T: git git://github.com/srcres258/linux-doc.git doc-zh-tw F: Documentation/translations/zh_TW/ +TOUCH OVERLAY OBJECTS +M: Javier Carrasco +L: linux-input@vger.kernel.org +S: Maintained +F: drivers/input/touch-overlay.c +F: include/linux/input/touch-overlay.h + TTY LAYER AND SERIAL DRIVERS M: Greg Kroah-Hartman M: Jiri Slaby diff --git a/drivers/input/Makefile b/drivers/input/Makefile index c78753274921..393e9f4d00dc 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_INPUT) += input-core.o input-core-y := input.o input-compat.o input-mt.o input-poller.o ff-core.o -input-core-y += touchscreen.o +input-core-y += touchscreen.o touch-overlay.o obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o obj-$(CONFIG_INPUT_SPARSEKMAP) += sparse-keymap.o diff --git a/drivers/input/touch-overlay.c b/drivers/input/touch-overlay.c new file mode 100644 index 000000000000..007dbd994474 --- /dev/null +++ b/drivers/input/touch-overlay.c @@ -0,0 +1,399 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Helper functions for overlay objects on touchscreens + * + * Copyright (c) 2023 Javier Carrasco + */ + +#include +#include +#include +#include +#include + +enum touch_overlay_valid_objects { + TOUCH_OVERLAY_TS, + TOUCH_OVERLAY_BTN, +}; + +static const char *const object_names[] = { + [TOUCH_OVERLAY_TS] = "overlay-touchscreen", + [TOUCH_OVERLAY_BTN] = "overlay-buttons", +}; + +struct touch_overlay_segment { + u32 x_origin; + u32 y_origin; + u32 x_size; + u32 y_size; +}; + +struct touch_overlay_button { + struct touch_overlay_segment segment; + u32 key; + bool pressed; + int slot; +}; + +static int touch_overlay_get_segment_props(struct fwnode_handle *segment_node, + struct touch_overlay_segment *segment) +{ + int error; + + error = fwnode_property_read_u32(segment_node, "x-origin", + &segment->x_origin); + if (error < 0) + return error; + + error = fwnode_property_read_u32(segment_node, "y-origin", + &segment->y_origin); + if (error < 0) + return error; + + error = fwnode_property_read_u32(segment_node, "x-size", + &segment->x_size); + if (error < 0) + return error; + + error = fwnode_property_read_u32(segment_node, "y-size", + &segment->y_size); + if (error < 0) + return error; + + return 0; +} + +static int +touch_overlay_get_button_properties(struct device *dev, + struct fwnode_handle *overlay_node, + struct touch_overlay_button *btn) +{ + struct fwnode_handle *btn_node; + int error; + int j = 0; + + fwnode_for_each_child_node(overlay_node, btn_node) { + error = touch_overlay_get_segment_props(btn_node, + &btn[j].segment); + if (error < 0) + goto button_put; + + error = fwnode_property_read_u32(btn_node, "linux,code", + &btn[j].key); + if (error < 0) + goto button_put; + + dev_dbg(dev, "Added button at (%u, %u), size %ux%u, code=%u\n", + btn[j].segment.x_origin, btn[j].segment.y_origin, + btn[j].segment.x_size, btn[j].segment.y_size, btn[j].key); + j++; + } + + return 0; + +button_put: + fwnode_handle_put(btn_node); + return error; +} + +static void touch_overlay_set_button_caps(struct touch_overlay_map *map, + struct input_dev *dev) +{ + int i; + + for (i = 0; i < map->button_count; i++) + input_set_capability(dev, EV_KEY, map->buttons[i].key); +} + +static int touch_overlay_count_buttons(struct device *dev) +{ + struct fwnode_handle *overlay; + struct fwnode_handle *button; + int count = 0; + + overlay = device_get_named_child_node(dev, + object_names[TOUCH_OVERLAY_BTN]); + if (!overlay) + return 0; + + fwnode_for_each_child_node(overlay, button) + count++; + fwnode_handle_put(overlay); + + return count; +} + +static int touch_overlay_map_touchscreen(struct device *dev, + struct touch_overlay_map *map) +{ + struct fwnode_handle *ts_node; + int error = 0; + + ts_node = device_get_named_child_node(dev, + object_names[TOUCH_OVERLAY_TS]); + if (!ts_node) + return 0; + + map->touchscreen = + devm_kzalloc(dev, sizeof(*map->touchscreen), GFP_KERNEL); + if (!map->touchscreen) { + error = -ENOMEM; + goto handle_put; + } + error = touch_overlay_get_segment_props(ts_node, map->touchscreen); + if (error < 0) + goto handle_put; + + map->overlay_touchscreen = true; + dev_dbg(dev, "Added overlay touchscreen at (%u, %u), size %u x %u\n", + map->touchscreen->x_origin, map->touchscreen->y_origin, + map->touchscreen->x_size, map->touchscreen->y_size); + +handle_put: + fwnode_handle_put(ts_node); + + return error; +} + +static int touch_overlay_map_buttons(struct device *dev, + struct touch_overlay_map *map) +{ + struct fwnode_handle *button; + u32 count; + int error = 0; + + count = touch_overlay_count_buttons(dev); + if (!count) + return 0; + + map->buttons = devm_kcalloc(dev, count, + sizeof(*map->buttons), GFP_KERNEL); + if (!map->buttons) { + error = -ENOMEM; + goto map_buttons_ret; + } + button = device_get_named_child_node(dev, + object_names[TOUCH_OVERLAY_BTN]); + if (unlikely(!button)) { + error = -ENODEV; + goto map_buttons_ret; + } + + error = touch_overlay_get_button_properties(dev, button, + map->buttons); + + if (error < 0) + goto map_buttons_put; + + map->button_count = count; + +map_buttons_put: + fwnode_handle_put(button); +map_buttons_ret: + return error; +} + +static bool touch_overlay_defined_objects(struct device *dev) +{ + struct fwnode_handle *obj_node; + int i; + + for (i = 0; i < ARRAY_SIZE(object_names); i++) { + obj_node = device_get_named_child_node(dev, object_names[i]); + if (obj_node) { + fwnode_handle_put(obj_node); + return true; + } + fwnode_handle_put(obj_node); + } + + return false; +} + +/** + * touch_overlay_map_overlay - map overlay objects from the device tree and set + * key capabilities if buttons are defined. + * @keypad: pointer to the already allocated input_dev. + * + * Returns a pointer to the object mapping struct. + * + * If a keypad input device is provided and overlay buttons are defined, + * its button capabilities are set accordingly. + */ +struct touch_overlay_map *touch_overlay_map_overlay(struct input_dev *keypad) +{ + struct device *dev = keypad->dev.parent; + struct touch_overlay_map *map = NULL; + int error; + + if (!touch_overlay_defined_objects(dev)) + return NULL; + + map = devm_kzalloc(dev, sizeof(*map), GFP_KERNEL); + if (!map) { + error = -ENOMEM; + goto map_error; + } + error = touch_overlay_map_touchscreen(dev, map); + if (error < 0) + goto map_error; + + error = touch_overlay_map_buttons(dev, map); + if (error < 0) + goto map_error; + + touch_overlay_set_button_caps(map, keypad); + + return map; + +map_error: + return ERR_PTR(error); +} +EXPORT_SYMBOL(touch_overlay_map_overlay); + +/** + * touch_overlay_get_touchscreen_abs - get abs size from the overlay node + * @map: pointer to the struct that holds the object mapping + * @x: horizontal abs + * @y: vertical abs + * + */ +void touch_overlay_get_touchscreen_abs(struct touch_overlay_map *map, u16 *x, + u16 *y) +{ + *x = map->touchscreen->x_size - 1; + *y = map->touchscreen->y_size - 1; +} +EXPORT_SYMBOL(touch_overlay_get_touchscreen_abs); + +static bool touch_overlay_segment_event(struct touch_overlay_segment *seg, + u32 x, u32 y) +{ + if (!seg) + return false; + + if (x >= seg->x_origin && x < (seg->x_origin + seg->x_size) && + y >= seg->y_origin && y < (seg->y_origin + seg->y_size)) + return true; + + return false; +} + +/** + * touch_overlay_mapped_touchscreen - check if an overlay touchscreen is mapped + * @map: pointer to the struct that holds the object mapping + * + * Returns true if an overlay touchscreen is mapped or false otherwise. + */ +bool touch_overlay_mapped_touchscreen(struct touch_overlay_map *map) +{ + if (!map || !map->overlay_touchscreen) + return false; + + return true; +} +EXPORT_SYMBOL(touch_overlay_mapped_touchscreen); + +/** + * touch_overlay_mapped_buttons - check if overlay buttons are mapped + * @map: pointer to the struct that holds the object mapping + * + * Returns true if overlay buttons mapped or false otherwise. + */ +bool touch_overlay_mapped_buttons(struct touch_overlay_map *map) +{ + if (!map || !map->button_count) + return false; + + return true; +} +EXPORT_SYMBOL(touch_overlay_mapped_buttons); + +static bool touch_overlay_mt_on_touchscreen(struct touch_overlay_map *map, + u32 *x, u32 *y) +{ + bool contact = x && y; + + if (!touch_overlay_mapped_touchscreen(map)) + return true; + + /* Let the caller handle events with no coordinates (release) */ + if (!contact) + return false; + + if (touch_overlay_segment_event(map->touchscreen, *x, *y)) { + *x -= map->touchscreen->x_origin; + *y -= map->touchscreen->y_origin; + return true; + } + + return false; +} + +static bool touch_overlay_button_event(struct input_dev *input, + struct touch_overlay_button *button, + const u32 *x, const u32 *y, u32 slot) +{ + bool contact = x && y; + + if (!contact && button->pressed && button->slot == slot) { + button->pressed = false; + input_report_key(input, button->key, false); + input_sync(input); + return true; + } else if (contact && touch_overlay_segment_event(&button->segment, + *x, *y)) { + button->pressed = true; + button->slot = slot; + input_report_key(input, button->key, true); + input_sync(input); + return true; + } + + return false; +} + +/** + * touch_overlay_process_event - process input events according to the overlay + * mapping. This function acts as a filter to release the calling driver from + * the events that are either related to overlay buttons or out of the overlay + * touchscreen area if defined. + * @map: pointer to the struct that holds the object mapping + * @input: pointer to the input device associated to the event + * @x: pointer to the x coordinate (NULL if not available - no contact) + * @y: pointer to the y coordinate (NULL if not available - no contact) + * @slot: slot associated to the event + * + * Returns true if the event was processed (reported for valid key events + * and dropped for events outside the overlay touchscreen area) or false + * if the event must be processed by the caller. In that case this function + * shifts the (x,y) coordinates to the overlay touchscreen axis if required + */ +bool touch_overlay_process_event(struct touch_overlay_map *map, + struct input_dev *input, + u32 *x, u32 *y, u32 slot) +{ + int i; + + if (!map) + return false; + + /* buttons must be prioritized over overlay touchscreens to account for + * overlappings e.g. a button inside the touchscreen area + */ + if (touch_overlay_mapped_buttons(map)) { + for (i = 0; i < map->button_count; i++) { + if (touch_overlay_button_event(input, &map->buttons[i], + x, y, slot)) + return true; + } + } + /* valid touch events on the overlay touchscreen are left for the client + * to be processed/reported according to its (possibly) unique features + */ + return !touch_overlay_mt_on_touchscreen(map, x, y); +} +EXPORT_SYMBOL(touch_overlay_process_event); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Helper functions for overlay objects on touch devices"); diff --git a/include/linux/input/touch-overlay.h b/include/linux/input/touch-overlay.h new file mode 100644 index 000000000000..3e0db813dc34 --- /dev/null +++ b/include/linux/input/touch-overlay.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2023 Javier Carrasco + */ + +#ifndef _TOUCH_OVERLAY +#define _TOUCH_OVERLAY + +#include + +struct input_dev; +struct device; + +struct touch_overlay_map { + struct touch_overlay_segment *touchscreen; + bool overlay_touchscreen; + struct touch_overlay_button *buttons; + u32 button_count; +}; + +struct touch_overlay_map *touch_overlay_map_overlay(struct input_dev *keypad); + +void touch_overlay_get_touchscreen_abs(struct touch_overlay_map *map, + u16 *x, u16 *y); + +bool touch_overlay_mapped_touchscreen(struct touch_overlay_map *map); + +bool touch_overlay_mapped_buttons(struct touch_overlay_map *map); + +bool touch_overlay_process_event(struct touch_overlay_map *map, + struct input_dev *input, + u32 *x, u32 *y, u32 slot); + +#endif From patchwork Tue Oct 17 11:00:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 734610 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 781E64177A for ; Tue, 17 Oct 2023 11:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="XUtxCd+0" Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2047.outbound.protection.outlook.com [40.107.249.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B63BF7; Tue, 17 Oct 2023 04:00:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B0xMTsXpqwiqQcoRSGaDpNJI2vHwb+LNr6v0o2CLo3cNfGXYZEtqftO5Le3FwUyOe0n/Rqv0X4uyw7/vbf8/oMSZTVcOMIQM/tpknHDWYRZ7QydocVeRE4HAB9VIEYJMZkkHbEVoeV6Kz+2nwnZDYZ/gfupcg0JWr4O2eJo5bIvUh/YjCSMacEJi+0CnKoklswBGfmxbH5aqPvhj+gLntjRQ+ZaY30fPFalbHJF4oQVB23ys3jvFRv2p0gcMs9o/1hhliPFv324PbP7byle6CzM/nV2vrFE5D9JWXBN9PgrTxNI3Hj1tIxCLvcIf87ifgKCz9ngl5Cfmq7fkst2+1Q== 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=s7bJxCqTJ9g4MIATbCMC0K8OKp28hAs7h61w97OYN30=; b=Rm6hkdbZ74HwK/nNGAz1UeN6O4bykfglO6wxnp4Y/iDukE0DCTtU2NVgkAOkI9tEu0GlDTe0FqXSKXUJoTSqRh9ocCfoTe4LpHz4f9yKf5eFAHzDoBL9oNjMWOyne+9KoCKfeIGpWNXN0Sb/Kh55kuOrhWfzooZID1Gxv2zYIXzWqHRw210s1hCS457EcAdF7KzXVUuAzi2J76W5d7TQOjG9/3HqFf8yh6ju2bh9T2rwU6aGviEmPK59hACMtps/uVfYnVLT6sgSZNAUaJfSBvDi1w1fT324CH5ZPS/PRyPgWHfFfdUyczLJXRayJVJt50C+9ulAzd+lZRCyxVpCvQ== 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=s7bJxCqTJ9g4MIATbCMC0K8OKp28hAs7h61w97OYN30=; b=XUtxCd+0Wldq3JggtckXspZtPVEVTDqjXSH8TIt9i//ZHWIo5w6TMs0/CFayZi3H9X02bW6VymEFzayAMuCML6dJkdYwzJQ2RYUZ9nXfrm3mj+r9GlL694CtJxhyvS2rBJffIZqv1yafwQcz7ZT1txJjeXhjK7ejIwtNkJNYNEY= 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 AS8PR08MB6295.eurprd08.prod.outlook.com (2603:10a6:20b:295::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Tue, 17 Oct 2023 11:00:16 +0000 Received: from VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::bc92:216b:11ed:db63]) by VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::bc92:216b:11ed:db63%6]) with mapi id 15.20.6886.034; Tue, 17 Oct 2023 11:00:16 +0000 From: Javier Carrasco Date: Tue, 17 Oct 2023 13:00:10 +0200 Subject: [PATCH v5 4/4] dt-bindings: input: touchscreen: st1232: add touch-overlay example Message-Id: <20230510-feature-ts_virtobj_patch-v5-4-ff6b5c4db693@wolfvision.net> References: <20230510-feature-ts_virtobj_patch-v5-0-ff6b5c4db693@wolfvision.net> In-Reply-To: <20230510-feature-ts_virtobj_patch-v5-0-ff6b5c4db693@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=1697540413; l=2380; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=1LZHOKMnwrpCeQ2+qaEcztfZHfZu03BFbjJG0+mOSG0=; b=w7WigiRzqN4MYZGEwYUBbZ/8FDWA3dLCYshizEXgtxJYWAi05xD+3e9pfGquhb2hAKhlPltbc Io7nKxUKK3YB1lEEoU6fDucrSGDl3cgvttsml7Q4EbU3IIpRS7XtPRQ X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1PR07CA0250.eurprd07.prod.outlook.com (2603:10a6:803:b4::17) To VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4974:EE_|AS8PR08MB6295:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d35a0a1-cb80-491b-3b9c-08dbcf003e9b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FQPUpZPh3LSfGD1WZwS07NDUjK/YdEKyA8aTEo0RCwmB9uRqvNSgUpnP+2eC15VljqUVQt8p/5N5ZmxF9E0AxqUnKWZINRPRCT5RKBKU/S3uSSoPoxF8LkiT07qbzlhSQuYxXcsxRTsHklRafL/xOscLfZPYLVrFczw7COtuzlwf48rUO5pkn12ovvWwAfXZAeEvJZr2DqgjEA4yr4PEQluyjOd2RULYc9poIkaETcmiQ3NfNq8pBIYIojn9XlqyHjDZVOTAwpq81AKzAOETmvQzF6p4ZENXE/UGRMWjI00S2AprdTkrApZxEkVX+39Q2qGnM+iTuKQOThNsAC8zctetJeQpqetnDhlbYEW9xeUGYXFO+IwNGKQMxCE3LITY+NdHCmCAOUdRcUXeleR6M/9hmakKKo09oHmrxow4KdsDlf2msYhm2dtwnnJnA0fs0VaqgOsx+3WVmxxPCbB50DbXudD9A2tL9sl7fgX6x3bLerbQlCrIDaaatujEkdWGE1/rvyRah9sQFn0PZ6rk5na0trVEgS/cIBtX1Qtou6Fe7WSwTwCw0CXdHPRwJSQ+YhIHL4Xs1TzK3KRTn2KfRycbHzF4Iz+HofpzSlGVn/BhiCSEVViBAiWEgsd6ojh4 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:(13230031)(136003)(346002)(376002)(39840400004)(396003)(366004)(230922051799003)(451199024)(64100799003)(186009)(1800799009)(107886003)(478600001)(38100700002)(52116002)(6506007)(2616005)(6486002)(38350700005)(26005)(6512007)(6666004)(41300700001)(44832011)(5660300002)(4326008)(8936002)(8676002)(316002)(66946007)(86362001)(110136005)(2906002)(66556008)(66476007)(6636002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?eKHVcGeHAAfrwoZaOmsCNZ4HbkjI?= =?utf-8?q?UekLXg234201EDaYTOWmissMrpKRh+crTXYD+nZPu/I64sSky/YXANzlyrUy+gj8r?= =?utf-8?q?eBrN8UfwJT6yt23NA18G1UKxINVfL72RRbYYMNMiToE1LTITyCxs3ywrbiFb2Cb6w?= =?utf-8?q?1S0lhl9B+ZjhfAFJ2oCJlMeDwbBRz/GAzcoeiaXjyTa9f7P1F2NrfOrGy+yh4xLeY?= =?utf-8?q?ix5tDZ8Z9IsnMx8WN/BZqSZCR4mrv4h4Gh1J5CltUT1yxFqJkEyFYovECG+5QYjue?= =?utf-8?q?lz6JO36JfT6FLqs0RhM7qM1WXDrjg/Q0URGefMqjWJt3rToIFKLcTNH0+N1+Hvb7m?= =?utf-8?q?pMuc5rjIA3NpjotMptA1gjgQCjsKlsYP/KHkJskvK6r7s2vqhHfWpjF2ZlJ3Y0/qv?= =?utf-8?q?9+6b/tc/S6FwR4i8xklJs+v7qA1ZPQqhUMdaQj9vSo3+XXWOfSUax5vcVZQSKTuTX?= =?utf-8?q?aHjDhC2nwOBs77zY5ypOhWDg1uOGZVa2Zpwoz7bOWsRy7KCNtSMtuIPidkznla1+8?= =?utf-8?q?RKuBfodoASHW7qoXK0+vuHRUi2BwyeI+JHTiTryHuhZOeXTvRSvdUj+LxraS+8AxB?= =?utf-8?q?8aewb31NWh4p/IYxvguHIUkUJC2gQq+IJFI3XZbQnkCa0ir0dl/Vxce6HYu61De+l?= =?utf-8?q?CPqhMbvf0G3+RgUYpgzs55G38Ii8uiBXs7Lct5JETM5aMKh7wP1YFC2gWaQRHGzCh?= =?utf-8?q?Q65qd2yB7r79XYaXX8z9lwnxa8pbStVbOSCJuGtIErs9KrnoiRmnn6XZ0jFy6wkIJ?= =?utf-8?q?fAWTUJQnbCZjWa5JAkFWAyCCDI8PcTUI/PWaJUYx/9iw54g7ECdjxMcgXPU3hd2Ri?= =?utf-8?q?hleBqLmUDuRY+uFQEIWxw/DnD30wn8fjuyYMMDRvCCTVYtp5Z72oY27rPda+Sw3zJ?= =?utf-8?q?wOGboh84M/hDA0UxPaTZjci73Jl7nzShWs3na5GRz1wKU4LlZBT+MMRmjh7Ti7MlC?= =?utf-8?q?3KVeUwBxl4yO/Akz1isBSyuJ8vkczwxqX8M5m+aEz7rKyjVxuiu0FmcJHzKdyZFaW?= =?utf-8?q?dDVP255bNmdNh3ztiaGvu1mcUnVMfmNsogGHpSWOGDJrHwTXPHhUiB/k0z/dS7S/N?= =?utf-8?q?FtOZuo/qw4rJdplnVF1wTSlS6dqaY9GixX1gao1CRjPJQf4DJ9mlqS7OgkzTdL/W4?= =?utf-8?q?fQkls5/fREsPIKlIZ3VWcGtJryr0kIJea4SWpDFc5gbFx2fJgcNQ8WHU167ntbelk?= =?utf-8?q?ILb9R1Fy8hicG0/KzTa9mqQT7fX/DycZMPbsXQpRQ40WGZdzZqcwfPXkovNUZEbQA?= =?utf-8?q?b7LLQt1++ZpEo/02GH7eqRS4LbfNcpQN8SgETqzXA0vTwNtscheUorc/5kO50KomN?= =?utf-8?q?TLY+dcqdlU34LZbOLKa9qK82fPEjd/QatCPm55HVZQC+0CLcEnR4oIIytUPvVYTcn?= =?utf-8?q?zOIrrGo+9AquOz60Zx765c5+8/QejtsaZYLPMQTEl1rv0nLYLAfMEWagLGpMhE0qK?= =?utf-8?q?EbYD1cyhOjXi7w3gxTGXrmB3VHygZkOuPcUIRlhazF0p89hhC416l8X3tYgioB/U1?= =?utf-8?q?gKbqcZy7zzjNMqylJnkJE4bK+czqkTJCaEnni+dQqeOb46qZbH4o8fg=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 5d35a0a1-cb80-491b-3b9c-08dbcf003e9b X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4974.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 11:00:16.1687 (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: Pa25oFj+U583y1Lgy6cdZYVvyQiDyAlojOh7fOatR5FlFBkHIL2WZgPnxl2Q4+I/DZ5UTjj3x/EYD6Y1kBudPTNdkFcHz5uks20Mo0EopQg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6295 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net The st1232 driver supports the overlay-touchscreen and overlay-buttons objects defined in the generic touchscreen bindings and implemented in the touch-overlay module. Add nodes for an overlay touchscreen and overlay buttons to the existing example. Signed-off-by: Javier Carrasco --- .../input/touchscreen/sitronix,st1232.yaml | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml b/Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml index 1d8ca19fd37a..f33fc0113a67 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml +++ b/Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml @@ -37,6 +37,7 @@ unevaluatedProperties: false examples: - | + #include i2c { #address-cells = <1>; #size-cells = <0>; @@ -46,5 +47,32 @@ examples: reg = <0x55>; interrupts = <2 0>; gpios = <&gpio1 166 0>; + + overlay-touchscreen { + x-origin = <0>; + x-size = <240>; + y-origin = <40>; + y-size = <280>; + }; + + overlay-buttons { + button-light { + label = "Camera light"; + linux,code = ; + x-origin = <40>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + + button-power { + label = "Power"; + linux,code = ; + x-origin = <160>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + }; }; };