From patchwork Thu Aug 24 13:17:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13364138 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 74CA4C7EE43 for ; Thu, 24 Aug 2023 13:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240811AbjHXNSF (ORCPT ); Thu, 24 Aug 2023 09:18:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241008AbjHXNRx (ORCPT ); Thu, 24 Aug 2023 09:17:53 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2051.outbound.protection.outlook.com [40.107.8.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D80691B0; Thu, 24 Aug 2023 06:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DqRRfbKOeerPOyD0VOYcZYAJo61tWPYrqyJGtY7O+XANjdGsbAuqU0U+TfJc5/4v5cv7H+/12ze4OZHN2DSy0dsN0rLxbE7Ch/WQHLJVVvH8Lh1JmcmmVtMna4YNmF4uUqrSoNbnolEicBDUlNqSICJAM2e/XJyPaPDx1eyxcH5ZoO/vwlc4aVHm+tGrs8gpBzqg8QZUVkY8SWjJ9mv9FmU8Enb/aH4mmoih2Hg/qtTGv6Q3iEXxjFrEh06TpOYmVDk+HdPlgCRA1aPbj54FCVCrmFIbi0Dh9DZF0918Mc8Ft+hgqQL6bLYgVFBIM2YgqIppR/YriGnpGEwLlCe8oA== 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=6s+e6xOeLPB29hou1wYdBocfusQeBy7NbBpEtLp6KMQ=; b=WjRdTHfwaIlIF4OMRo/kbKXkkX1PiAap1FdkmBlexXc9Yf/K4CLVIaeXRBACgbPEhIHYVT3fI13y5tMrm1KolQvFu7h77ajAapcSvq6uB1j+83mw0kgmdCcLWbe8m+P6XbyXPSWRz2tdUZ+/bSH0FYWjc0WXRGQNrLCzjVpiOXowKDRcHqHYT/DufGf+BEvIEwtlefhks8LmGOzG1um9YVMjuK+RE1lphF7BjINSdJjZ1q82H8mdSgwQRgay8OS+oNDap8NxHanuTmMx+sVewEV3LbhH1Hj25p7nfLXceAA8jbmBxmcC/oUuOM808AqCBjb85GcGSPYmqFfngwXhIg== 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=6s+e6xOeLPB29hou1wYdBocfusQeBy7NbBpEtLp6KMQ=; b=SYnKLykSaLZ4BXAU83IwiuxvP0sKGyilSiAk8H51Fm1ob2NdHG9pTVnFJyFvo825RLInc6+C3U9AApuwkZJkBY4A6ITJaq2N1irGmzVdCs5KDidGcyKglxPDRVP4X720vf04j2tluxmTXThwE/zVjr5zQF3o/vgt64D8Qt12F0g= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wolfvision.net; Received: from AM6PR08MB4966.eurprd08.prod.outlook.com (2603:10a6:20b:d4::23) by AM7PR08MB5397.eurprd08.prod.outlook.com (2603:10a6:20b:dd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.24; Thu, 24 Aug 2023 13:17:46 +0000 Received: from AM6PR08MB4966.eurprd08.prod.outlook.com ([fe80::f7b3:4adb:c638:d8c7]) by AM6PR08MB4966.eurprd08.prod.outlook.com ([fe80::f7b3:4adb:c638:d8c7%6]) with mapi id 15.20.6699.027; Thu, 24 Aug 2023 13:17:46 +0000 From: Javier Carrasco Date: Thu, 24 Aug 2023 15:17:11 +0200 Subject: [PATCH v4 3/4] Input: st1232 - add touch overlays handling Message-Id: <20230510-feature-ts_virtobj_patch-v4-3-5c6c0fc1eed6@wolfvision.net> References: <20230510-feature-ts_virtobj_patch-v4-0-5c6c0fc1eed6@wolfvision.net> In-Reply-To: <20230510-feature-ts_virtobj_patch-v4-0-5c6c0fc1eed6@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=1692883063; l=5477; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=wCiL2h9+IZtOVcDxQziwk7mw/m8sSJBkQv4/SlZOqeA=; b=0aOfbqGOID55D2nKAGaVEbrDuMotGy/iif1NwUDFWaqqnWatCMyUAOt6UPNerHI7gdYb3lAl1 0ajP6u+cIqhCFc78JDet3JdLtw6LxkU18+m81uTC1nAq25ZviGigxY0 X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1PR07CA0301.eurprd07.prod.outlook.com (2603:10a6:800:130::29) To AM6PR08MB4966.eurprd08.prod.outlook.com (2603:10a6:20b:d4::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR08MB4966:EE_|AM7PR08MB5397:EE_ X-MS-Office365-Filtering-Correlation-Id: 03bae396-59e7-483f-45cc-08dba4a481f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uzxzANlSCC/Y3qlm5V8TfmINqlkWfqyXoI5P6t7I+8uHtytO/UHrUmYbJi4E/Fzolr6/vzQ7uOVxQHnSioevCTrdN9TDF2mmsHOZHhxGmpXC4SB1JyUwQ4xdnMhnGeoEMM01rKJaKykJRtRe1nzIz2d9G7bkUdEg/JDskml3F7cv0dK9UCwHQvOOgQiuGGbdu1I7ifn8/9aclGdUJuC3qobSd6AkVyIZ0Sq8mj7FUoLVBq7rKaDXWH7SdlqRYKp77qCFpS2lHB4zgsR4VYjEJ4NzgJx0RRuH7Gm+1JVoiyaY9x5/7q7kxaKJzwiEhbbfChP35sgEc/piVfS/EDH0jbs9Q0l0A/rQx+goCSts4GCgJY1WQAnjabAWD2/3HUZqEchpycnH61YyvK8QO+D4DMjUjo6H7cPgBgSxXqjDwcpmviL7WygcrwRK2or0V2vJkMnU8rmMhpQxN7aqrgqOJNWZXnG/82EAyFifO34LqosRh4g9p/+evlxX74pAbkjlcxF1fkLvK/StYbD60uHXEMtCQkWCOhQsrxYsLPWXcMfAoDp7WGWScm0PKo7DPY2hcn1A9WRkNrIuL85KSZ6taBEJV0ye9Hk2Qr4UFXM9+k2XXDajvGH6bt5yjKhSiDSu X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR08MB4966.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39840400004)(366004)(376002)(136003)(396003)(451199024)(1800799009)(186009)(2906002)(38350700002)(52116002)(6506007)(6486002)(5660300002)(83380400001)(44832011)(26005)(86362001)(38100700002)(8676002)(107886003)(8936002)(4326008)(2616005)(66946007)(6512007)(66556008)(316002)(66476007)(110136005)(6636002)(478600001)(6666004)(36756003)(41300700001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?w3vk+fC43/fEyRnwRwqx4wLWaYkh?= =?utf-8?q?ohqxayzB0uZlTUdwIFxhpR6qgCBTLgy7U+Lo61emYeufc2kh0fA6/mly1C+auoW8Q?= =?utf-8?q?Ps7KsEgF/TxstnozGRbG0sEouWuEcZ/CLj6Yk0Av0Y1xyLKv68Wudm0DkrHFUHWQ9?= =?utf-8?q?zl8kC9MrZdRS3lj6SUqLy0YaYLKYSFFYcBtUnPZd831Np75vh/3E/B8CTbXqwNfrp?= =?utf-8?q?o3xO3+njBliYFV9Tq9i+YY4w9mfM6vNAzeIV01T1XpR6xqQbKZkjY8PbXAWjjWDs9?= =?utf-8?q?xdEJAPtAtu9YBUCGUS5tczAoRgtE2Z0vUvNVtDYaUgmKj++v31451rTUsC6ftCakC?= =?utf-8?q?hHZ7ycN/1hQO+78av3j5ZqqYU11Y6EbCW78GLjS4MmfuSd7eKupi3+i/0c4WyPDd0?= =?utf-8?q?iP4++IIOsC4cJzNn1XNm5uMDXZmYg1TfZu6FZs5WqgRld+aUnV1mG5e2gdcalwPzj?= =?utf-8?q?DB+HlBCTonJPVH1ERTfc3D7/qduJu6BVufHafvBXpzCpOZ60v6dWKTtVk21BsTl92?= =?utf-8?q?Ou6+7HtQAWhYkulpZUkt2nCUIggKmW3oruUqOzXNCueEYJAJvZPYrw9vQJNahq19A?= =?utf-8?q?EziF0q2lwFPUG0d+grjj9nofJFMO+Kd9S5/IUT7S+cVImkQwFQC+ygD8PUUU7hEzn?= =?utf-8?q?8ilAIgiBP7WPnQ44lBMgiLp1wMqqXqibHuDvd6fxRquy8dUr857DqUwmdH5xhz8T5?= =?utf-8?q?0SXUMzJT4LjBTnLwkz37CY0upVcQxTZWc1IKuId4M1g2kDAj53m+cQnGWSC/DPa4n?= =?utf-8?q?CnSHTVL+bGtOM6CXiPAvOHsb61DZI560bWCypmzJ1cSsSRU+69o8gxZoPRTlkhMYd?= =?utf-8?q?jLdbjY7hPB+K/sp+ThXmND+j7N3FmdL2LOUbdaTUO6s1hRwD/f9aK4zyvLe+SVHHc?= =?utf-8?q?wQvJ/7OkVkNXYrHhxIKCP5uiSGssHnfIks5LTyBJ/OAtqHgebOUsb88jQIZtj2zjB?= =?utf-8?q?5VSCwQMxdfV5VSYai8x6E/lLMNIx7EZwYgMXoesyZQ1bSzPt2PK1/K3nbiYDWtETQ?= =?utf-8?q?oEaytkWP2MJUW94kExIf1dhWk5CRif0to6slCjqwtInzv9bB9mK6q1xx32iIZmefO?= =?utf-8?q?224gB5R6UrlmjHLV7nm1enqMkxL9/2gbqGRvWKtbLPE+WErjDvwbcUDMGK1jXtpzm?= =?utf-8?q?x83TxOGa11yRkzuP5qhwH7AfEhaRsxlfD74L+ZQDDAIGvRRl2rePNCGm5Qly630mc?= =?utf-8?q?XO93OxdSN+bi2JewJnaVgv+O2oP/MI9CETdrNffTVcaQOjbuOYigzdIrEn/0cp5FX?= =?utf-8?q?CmZA9Xe0nEKWIvyFeBsOffe9/rom/MPjRlSBSYusd2OJmoX/XhVoNOlhKN/Xhwx/0?= =?utf-8?q?yAzGSVmocIso4+Q9Rtn3MmYM2oY+afdGFnbzkS9u8VTi++hvrd/tORSlViv5GgAEj?= =?utf-8?q?M4u3qFLo2TWX+Ih9+KvGFjmHdWj9gBplNA8iErU1XRmHdjAakUYeA+wwt+00Ryp1u?= =?utf-8?q?0BORynteyBOGM0y18EXkCLr8p+dZoPhdPumE7r5TOs09I59k6y3A4hpzhkSyi71jl?= =?utf-8?q?IIjibUDaxIIChblGmJxHQ+fk0BHbi+/i/aQdl7oH2Yo5QthrJ+T0sIY=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: 03bae396-59e7-483f-45cc-08dba4a481f1 X-MS-Exchange-CrossTenant-AuthSource: AM6PR08MB4966.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2023 13:17:46.6001 (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: K/0pud9y/jNMjk6SW5LH6UFVlM2YK9Vd42JJJVFUZNkkiNU3uhvmDzaGGEdu9DMpfqqk97gYTtp6xuHrEFT26TrGi3G3WXMYs1WeF0wz5Kc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5397 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Use touch-overlay to support overlay objects such as buttons and resized frames defined in the device tree. If an 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/st1232.c | 70 ++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index 6475084aee1b..d22f7d57f468 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 touch_overlay_map *overlay_map; const struct st_chip_info *chip_info; int read_buf_len; u8 *read_buf; @@ -130,6 +133,7 @@ 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 *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]; @@ -138,14 +142,20 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts) for (i = 0; i < ts->chip_info->max_fingers; i++) { u8 *buf = &ts->read_buf[i * 4]; + bool contact = buf[0] & BIT(7); + unsigned int x, y; - if (buf[0] & BIT(7)) { - unsigned int x = ((buf[0] & 0x70) << 4) | buf[1]; - unsigned int y = ((buf[0] & 0x07) << 8) | buf[2]; - - touchscreen_set_mt_pos(&pos[n_contacts], - &ts->prop, x, y); + if (contact) { + x = ((buf[0] & 0x70) << 4) | buf[1]; + y = ((buf[0] & 0x07) << 8) | buf[2]; + } + if (touch_overlay_process_event(ts->overlay_map, keypad, + contact ? &x : NULL, + contact ? &y : NULL, i)) + continue; + if (contact) { + touchscreen_set_mt_pos(&pos[n_contacts], &ts->prop, x, y); /* st1232 includes a z-axis / touch strength */ if (ts->chip_info->have_z) z[n_contacts] = ts->read_buf[i + 6]; @@ -226,6 +236,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 *overlay_keypad; u16 max_x, max_y; int error; @@ -263,8 +274,13 @@ static int st1232_ts_probe(struct i2c_client *client) if (!input_dev) return -ENOMEM; + overlay_keypad = devm_input_allocate_device(&client->dev); + if (!overlay_keypad) + return -ENOMEM; + ts->client = client; ts->input_dev = input_dev; + ts->overlay_keypad = overlay_keypad; ts->reset_gpio = devm_gpiod_get_optional(&client->dev, NULL, GPIOD_OUT_HIGH); @@ -286,24 +302,37 @@ static int st1232_ts_probe(struct i2c_client *client) input_dev->name = "st1232-touchscreen"; input_dev->id.bustype = BUS_I2C; + overlay_keypad->name = "st1232-keypad"; + overlay_keypad->id.bustype = BUS_I2C; /* Wait until device is ready */ error = st1232_ts_wait_ready(ts); 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->overlay_map = touch_overlay_map_overlay(ts->overlay_keypad); + if (IS_ERR(ts->overlay_map)) + return PTR_ERR(ts->overlay_map); + + if (touch_overlay_mapped_touchscreen(ts->overlay_map)) { + /* Read resolution from the overlay touchscreen if defined */ + touch_overlay_get_touchscreen_abs(ts->overlay_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 +364,19 @@ static int st1232_ts_probe(struct i2c_client *client) return error; } + /* Register keypad input device if overlay buttons were defined */ + if (touch_overlay_mapped_buttons(ts->overlay_map)) { + 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; + } + } else { + input_free_device(ts->overlay_keypad); + } + i2c_set_clientdata(client, ts); return 0;