Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2146500pxk; Sat, 19 Sep 2020 14:43:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcQ6Uj2OWFFqafviZmRBaiOoo+TbJVrev+o9zHVmUQJY0c0WlSAkOz5kc3Xdah2qACX9w0 X-Received: by 2002:a17:906:3e90:: with SMTP id a16mr40253223ejj.363.1600551801035; Sat, 19 Sep 2020 14:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600551801; cv=none; d=google.com; s=arc-20160816; b=Tfbm1D3tSX9jnyOd3ThWqTf94pTqbODRmMb7Xy1sc01KhUm4NGZtEmNPMqHxeHlZ6F 4n0zxfX9wrrWtQBSJWwPjLQaUA8eX6Dxiup2GHIBm6gDI1aNCQ3Q4csIKhdyacNsuezJ 15NhsoJYH2sJeSg9MZqWFGSmeiNVEKeC3/QbJ84/aQXHa5GwGmaNnodaAucF9fWvZEPq qP8Ky4+hSNldHXXc7tLZIaP3tBSJrKKoK1M+HOYz01sbYO5cmNCcnXJTpBS1/eDz1fJ7 5F3kZ72l2RaKubwHfQF/0U2qEswR6XYfYqmqDdtuNPWx5FQr3ZDuH7OUvlejUe4rIChG B3/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:content-transfer-encoding:mime-version :subject:from:references:in-reply-to:message-id:date:dkim-signature; bh=SPwdtJNfCi13XI+eQCir3ZIu13dtAN84AxR2GeGdrh8=; b=itgnSku+w9BWPnGZ8uwHj4UDvtYjTzZY6bISKwnLgGp9QK7ksqxL3JlVw+19TEdbuH 6u4aLtXWu2w9naIe+ZaZRD3p6kj11CrZw4yzVQgqk1EIbkmv5K8pQhznQG9QuDYoByjq PvvQHYfgWZXPl4G6LRVCrAeacX4Hmtwtqz2BNx+dkoF/hGYUVdtWIRS0z4xhvGjnQWzV OG55a6psQ2t8l75DtkvLUkGma1A0dssh885Sv3rtHXSYfBXD7g2LRJRyGQhiwx1RPgtU wpyaVWuVgaQwDCEPKtlK025mgOfvJ6qaRr9VQ/uNUYmOBGenAGAVM0cQZjTefpjUGnuE D/qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=Ejy2x38J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z9si5167468ejj.34.2020.09.19.14.42.41; Sat, 19 Sep 2020 14:43:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rere.qmqm.pl header.s=1 header.b=Ejy2x38J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbgISVl0 (ORCPT + 99 others); Sat, 19 Sep 2020 17:41:26 -0400 Received: from rere.qmqm.pl ([91.227.64.183]:49041 "EHLO rere.qmqm.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726696AbgISVlZ (ORCPT ); Sat, 19 Sep 2020 17:41:25 -0400 Received: from remote.user (localhost [127.0.0.1]) by rere.qmqm.pl (Postfix) with ESMTPSA id 4Bv402664bzcg; Sat, 19 Sep 2020 23:41:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rere.qmqm.pl; s=1; t=1600551682; bh=sjHesEuhUQBPTBR5PKdh6Su6/OO5b6xTTe6dLO4s9HI=; h=Date:In-Reply-To:References:From:Subject:To:Cc:From; b=Ejy2x38Jl2CufmcXcBr0JO0Vfrc+ZlEVXVGRqVHCRKcgy3XgwPm0gyKFSj+n+XO9J Jpwfh4PxPU/Slwv5DG75tQQz92wkcVQRFpF+VDNpYvUJr0m3qXW6ON7O7eYz8zC/u+ 4Ppmy9BwGfj9EXvQOPrgAn4v+ncAsOroFeBCgYkqzl/XNhCjT4D/s1hUfAwf6y79IJ mLr84Qv1qLxfW5x3F9aGzG9IvLXIQOxCnezAlyf+Qy5X/8hLuWqmM7noJY17Upmr1Y 9/Xi65lZHG08RH5LrJ964e1sxmsvtKTkKwZPaTLgPEuAXIhvztJUmpVr+9GIc5mIJO FTa6BjvVzdXkQ== X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.4 at mail Date: Sat, 19 Sep 2020 23:41:22 +0200 Message-Id: In-Reply-To: References: From: =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= Subject: [PATCH v7 3/4] input: elants: read touchscreen size for EKTF3624 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To: Dmitry Torokhov , Dmitry Osipenko , Henrik Rydberg , James Chen , Johnny Chuang , Scott Liu , "Gustavo A. R. Silva" , Harry Cutts , Peter Hutterer Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org EKTF3624 as present in Asus TF300T tablet has touchscreen size encoded in different registers. Signed-off-by: Michał Mirosław Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko --- drivers/input/touchscreen/elants_i2c.c | 84 ++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 5 deletions(-) diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c index f1bf3e000e96..c24d8cdc4251 100644 --- a/drivers/input/touchscreen/elants_i2c.c +++ b/drivers/input/touchscreen/elants_i2c.c @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -43,6 +43,10 @@ /* Device, Driver information */ #define DEVICE_NAME "elants_i2c" +/* Device IDs */ +#define EKTH3500 0 +#define EKTF3624 1 + /* Convert from rows or columns into resolution */ #define ELAN_TS_RESOLUTION(n, m) (((n) - 1) * (m)) @@ -94,6 +98,8 @@ #define E_ELAN_INFO_REK 0xD0 #define E_ELAN_INFO_TEST_VER 0xE0 #define E_ELAN_INFO_FW_ID 0xF0 +#define E_INFO_X_RES 0x60 +#define E_INFO_Y_RES 0x63 #define E_INFO_OSR 0xD6 #define E_INFO_PHY_SCAN 0xD7 #define E_INFO_PHY_DRIVER 0xD8 @@ -157,6 +163,7 @@ struct elants_data { bool wake_irq_enabled; bool keep_power_in_suspend; + u8 chip_id; /* Must be last to be used for DMA operations */ u8 buf[MAX_PACKET_SIZE] ____cacheline_aligned; @@ -434,7 +441,58 @@ static int elants_i2c_query_bc_version(struct elants_data *ts) return 0; } -static int elants_i2c_query_ts_info(struct elants_data *ts) +static int elants_i2c_query_ts_info_ektf(struct elants_data *ts) +{ + struct i2c_client *client = ts->client; + int error; + u8 resp[4]; + u16 phy_x, phy_y; + const u8 get_xres_cmd[] = { + CMD_HEADER_READ, E_INFO_X_RES, 0x00, 0x00 + }; + const u8 get_yres_cmd[] = { + CMD_HEADER_READ, E_INFO_Y_RES, 0x00, 0x00 + }; + + /* Get X/Y size in mm */ + error = elants_i2c_execute_command(client, get_xres_cmd, + sizeof(get_xres_cmd), + resp, sizeof(resp), 1, + "get X size"); + if (error) + return error; + + phy_x = resp[2] | ((resp[3] & 0xF0) << 4); + + error = elants_i2c_execute_command(client, get_yres_cmd, + sizeof(get_yres_cmd), + resp, sizeof(resp), 1, + "get Y size"); + if (error) + return error; + + phy_y = resp[2] | ((resp[3] & 0xF0) << 4); + + if (!phy_x || !phy_y) { + dev_warn(&client->dev, + "invalid size data: %d x %d mm\n", + phy_x, phy_y); + return 0; + } + + dev_dbg(&client->dev, "phy_x=%d, phy_y=%d\n", phy_x, phy_y); + + /* calculate resolution from size */ + ts->x_max = 2240-1; + ts->x_res = DIV_ROUND_CLOSEST(ts->prop.max_x, phy_x); + + ts->y_max = 1408-1; + ts->y_res = DIV_ROUND_CLOSEST(ts->prop.max_y, phy_y); + + return 0; +} + +static int elants_i2c_query_ts_info_ekth(struct elants_data *ts) { struct i2c_client *client = ts->client; int error; @@ -588,8 +646,20 @@ static int elants_i2c_initialize(struct elants_data *ts) error = elants_i2c_query_fw_version(ts); if (!error) error = elants_i2c_query_test_version(ts); - if (!error) - error = elants_i2c_query_ts_info(ts); + + switch (ts->chip_id) { + case EKTH3500: + if (!error) + error = elants_i2c_query_ts_info_ekth(ts); + break; + case EKTF3624: + if (!error) + error = elants_i2c_query_ts_info_ektf(ts); + break; + default: + unreachable(); + break; + } if (error) ts->iap_mode = ELAN_IAP_RECOVERY; @@ -1266,6 +1336,9 @@ static int elants_i2c_probe(struct i2c_client *client, ts->client = client; i2c_set_clientdata(client, ts); + if (client->dev.of_node) + ts->chip_id = (uintptr_t)of_device_get_match_data(&client->dev); + ts->vcc33 = devm_regulator_get(&client->dev, "vcc33"); if (IS_ERR(ts->vcc33)) { error = PTR_ERR(ts->vcc33); @@ -1495,7 +1568,8 @@ MODULE_DEVICE_TABLE(acpi, elants_acpi_id); #ifdef CONFIG_OF static const struct of_device_id elants_of_match[] = { - { .compatible = "elan,ekth3500" }, + { .compatible = "elan,ekth3500", .data = (void *)EKTH3500 }, + { .compatible = "elan,ektf3624", .data = (void *)EKTF3624 }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, elants_of_match); -- 2.20.1