From patchwork Wed Dec 20 08:39:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 757703 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2051.outbound.protection.outlook.com [40.107.8.51]) (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 201E11D6A4; Wed, 20 Dec 2023 08:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wolfvision.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wolfvision.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=wolfvision.net header.i=@wolfvision.net header.b="g+cWobTZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iZcP6pdX+7gUNm2HLgMFTA9R1/pd951H56Df8zidPYxNfdXBU5ZS+IxM8JbYjK3QvPnXFEzMUggdjQJUsZuGChZtCYQ0G669A+nEHbwJe1JaNSaFrZv1onWbENlv+U+bdqRzMRAfSVZZOOSo7K+e7uAT/ZLQcFZDa6WBYTk5tgtDET/Qal/wGUi6mh4tmf5PUWiow6Lf2HRjHaUuf6+pikrEYUDxsMyiARkyoCR87Q0EaQo0ALFVH/72yvlZJ+tcFcw7GxeCN3N1K0ufEh6THiut5YBYtp37aaiQBvi3gHWDBl+c4bIpnF9jO95fqFiaCiRoe6BRGycOHhiXuFXATg== 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=2dJliw5bToQke3WfeUdjp5G1kxFNViFF+00Gz9vm6og=; b=bUIejdZISWkWAXYb7elbB0ZtiLRvi+EjV6v3lLGRcb8Iplo3J19AFiuzKSWpN0wHIO7/2YgVjrCRaK3/fC45HYT5mqFe5Y8K9fXrcCnCgDpaD9Aj5UKhWAuKmJL+PdObGunkq9HzTsjWVQHC8UMl/NbWlmRs0GF7nYbXRM766hOuJpy8Om7TyULMqDN/9kB9bZSJIX/rnYIOmQW/5mKjaFZg8od7NNFBm/aXdqpKaL4d0uGV5gK8vQjuW9umruVLx2rfsyiNjRxPym8c2ZOV2T0GxPjap2yfDVMil+2IwDYbzgd2L0CXlglMzdNsPzvIPPM078YVzEhzp3xXLA4+Ug== 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=2dJliw5bToQke3WfeUdjp5G1kxFNViFF+00Gz9vm6og=; b=g+cWobTZE/vFlvatSv5yd3f9V6X1DVmp/PlZKaWf4veIeh//1TM6UmL4Mn89JAVohnz9IP06W9Z8W5iaJkPWBuvDFIryZOdORd9H/p8SB2GFmxVb0dk36kIiBreznHd3+vYK0tF72L4CvcosW94/tsRx51X4F12zojrmrWOpLCM= 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 AM9PR08MB6114.eurprd08.prod.outlook.com (2603:10a6:20b:287::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.18; Wed, 20 Dec 2023 08:39:53 +0000 Received: from VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::6b40:1e6f:7c94:71dc]) by VE1PR08MB4974.eurprd08.prod.outlook.com ([fe80::6b40:1e6f:7c94:71dc%4]) with mapi id 15.20.7091.034; Wed, 20 Dec 2023 08:39:52 +0000 From: Javier Carrasco Date: Wed, 20 Dec 2023 09:39:46 +0100 Subject: [PATCH v6 4/4] Input: st1232 - add touch overlays handling Message-Id: <20230510-feature-ts_virtobj_patch-v6-4-d8a605975153@wolfvision.net> References: <20230510-feature-ts_virtobj_patch-v6-0-d8a605975153@wolfvision.net> In-Reply-To: <20230510-feature-ts_virtobj_patch-v6-0-d8a605975153@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=1703061588; l=5320; i=javier.carrasco@wolfvision.net; s=20230509; h=from:subject:message-id; bh=5l6dIl/NYW73Tl4xHQU1WZhPslhNKxcOjVzCX472s8k=; b=qSIXewiWUER8XL78l2IfugcIrm8vnXv0D6OSNSE33VjHncGYz1vBcRwowDeMMfrGIZB5C9bu5 5CFFjp8NkQtChVlFfdsIIJEPXaiatvTNUaIdpiGkTvn5rrY9FhbVHWy X-Developer-Key: i=javier.carrasco@wolfvision.net; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= X-ClientProxiedBy: VI1PR0502CA0028.eurprd05.prod.outlook.com (2603:10a6:803:1::41) To VE1PR08MB4974.eurprd08.prod.outlook.com (2603:10a6:803:111::15) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VE1PR08MB4974:EE_|AM9PR08MB6114:EE_ X-MS-Office365-Filtering-Correlation-Id: d0292b3c-689f-47fa-c811-08dc01373c46 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VSyjRzKWbxq1gg5O1gn2OAiM9R42U03KX2CWXGJTLk0LM3ovx9iV2+ojrebip33fsK9a+00X7bW6BGtgiOsJ6qXhh5WQJpkP+Q0uE1JDCk3WDz6BRzgqrCe4qSfR+7JLOFeE8WuCTw4KPqguxNYafSEPCV1nx9linPjcAWcR6kZ2/9VnCNdgp5HGtzJCj8Cw891G0jtcMqvEGMdRKlhfbf1XEqztYM/mjopkAXhsGkUpW/afZg+4IJZ4tD+abTX2mnUkP3WsZJ4EGGHSVYwB/HHy/X7OC2bw8H0U94AnV6m2La/nfveHtOPambpOIv3Eayd+PvCBjSLIPAhqflBvJlpsSK71ou9AAyZummBUrgojzSnfIKi9u3dR27+gLbUy7Dl0aVOU+OB12qJEj9ltbo4eX1rYScF8a1KB7z2iar07orlW4Qjv8j3l4HjVPYzvNPgGInz57DRHpbpFO7OsYog9IrVxub2LZw3zkRsnsEcvKPFtxLO8+wQkkbMIbyS7oaT9g2HAsN4GCoi/y84tNsPcOE1OWyMMbe4GlPA78hQGIr3I6iLAPzwy3XoxQIMZvUdsYF4Wd8m1FenArys7D/4w9zsiI4PcjkB4zX1YLP/PyJG3XEnMb9RpcTzHgFii 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)(366004)(39850400004)(396003)(136003)(376002)(346002)(230922051799003)(451199024)(186009)(64100799003)(1800799012)(26005)(5660300002)(66556008)(6636002)(316002)(6486002)(66946007)(66476007)(44832011)(107886003)(2906002)(38100700002)(4326008)(8936002)(478600001)(8676002)(52116002)(83380400001)(6666004)(41300700001)(110136005)(86362001)(2616005)(6512007)(6506007)(36756003)(38350700005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-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?7gy33VLE2rqZ1D44/aSEPF1hkged/20mFIjT/CeXUT4K6BEnSxWKj1LuobjXemFNr?= =?utf-8?q?+RiqO4nD8cJ0yPW1Ghs0nHIaWbW8FD9MIobD7noxjnf5SFhOX1t95YIFboFAJkdjb?= =?utf-8?q?EuIKvqkbRhC/Ou7EXH8eWXx85ffmqKnLKBhp5KOWlOR6daqw9yDYxD8yhOL5Uz0Sv?= =?utf-8?q?cYqW3IU+cUUXjKASjPdb38y6f065cJZS0BfrFdxXJdqWVxG1c+AKaGrwuWcAfB27q?= =?utf-8?q?x7E6LFI2QisdrY+kreALD1Br4ibmNih6voJpEvQ7NvhKcaQKF1fyi1hYoVdQ1XPPI?= =?utf-8?q?/BuqMNi1Q+mQ/mqS2bLK4ykv9Wpf34HDRMebO7qsx/kdkQnLKUUpnKPl5GBfiq5lk?= =?utf-8?q?GmmpPHMTQGP63D3hlB44yUJ8MhjxIaSf9Ti81nqRb1Y27cdlvTy4JeH64npQwMmuQ?= =?utf-8?q?xbwUlQxISquynIEuP0k40U768/qfsgpNbfz1ecCF/5HA77Tox1hmwHX9oetbvWh2J?= =?utf-8?q?C0IrKsr5unt0EhMr4iMsV9rx+MfQ+0rAawNeWPeHa7sWKcM3KhwNwMxa2rOFVqwel?= =?utf-8?q?BbJL+xX5pEBANLaUy2NN4O7QkgSWMOP7u2HayT0eOcL2YlnFZ3yAdZv4WHpvWyN8T?= =?utf-8?q?/VnrhWE9H7M1YxMfmHjrsTOnfuj0wJ04dhJQHMx6CiDvnXC3MWx7RzOGkBsODsAV9?= =?utf-8?q?IDrlAu5kG8gDC+YQVTq4McwjkutIxXJWLjTeKSsut4K05QqfMGFjxl0=3D?= X-OriginatorOrg: wolfvision.net X-MS-Exchange-CrossTenant-Network-Message-Id: d0292b3c-689f-47fa-c811-08dc01373c46 X-MS-Exchange-CrossTenant-AuthSource: VE1PR08MB4974.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Dec 2023 08:39:52.8580 (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: at+2ijy75fmjHGr/Nh/hNSv0d+LoxXK+4NSAEuuxWHonKorFx9WlYcTWjiUK5sKeR4djj9cQOnKLibkFfmmZgAInSmoRgei3WhejJ6VnHC4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6114 Use touch-overlay to support overlay objects such as buttons and a resized frame defined in the device tree. 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 | 71 ++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index 6475084aee1b..5684cf04bfa1 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,7 +57,9 @@ 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; const struct st_chip_info *chip_info; + struct list_head touch_overlay_list; 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->touch_overlay_list, 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,38 @@ 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 */ + INIT_LIST_HEAD(&ts->touch_overlay_list); + error = touch_overlay_map(&ts->touch_overlay_list, ts->overlay_keypad); + if (error) + return error; + + if (touch_overlay_mapped_touchscreen(&ts->touch_overlay_list)) { + /* Read resolution from the overlay touchscreen if defined */ + touch_overlay_get_touchscreen_abs(&ts->touch_overlay_list, + &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 +365,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->touch_overlay_list)) { + 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;