From patchwork Fri Nov 18 18:21:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lin, Meng-Bo" X-Patchwork-Id: 22426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp344089wrr; Fri, 18 Nov 2022 10:23:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ByFLHP/cxdWIh1B9XIZ9IMGiobRsp30nkiGQIeSVAHJdyu+BPHSsakoBzKonQpnGPhloU X-Received: by 2002:a17:90a:4207:b0:209:46fe:871b with SMTP id o7-20020a17090a420700b0020946fe871bmr15046123pjg.163.1668795803014; Fri, 18 Nov 2022 10:23:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668795802; cv=none; d=google.com; s=arc-20160816; b=VgCgw9Jz+6ouZ/I/bN9th9PrmNzSXIYPQar1LraqKnM9RiDo+mxPn7rdtYE3ttj6ks ymIGLvRFLJ25c/wEr6WgNAwHdi9FlqwPtA/7HZczXxw8e7/Lb9WdE1qmC8VQxrnN3sP/ rlSEHkonq/+2mxMVasZdfcnZiYhW+1hfA4HXcYLfEkO0Ut4G/TJ6bbyRQ1d7tfQISQcX Grf3tQHLjLR2UMm65wqRrubuwPrnL6JXm8SO2B8BiRq9IWrnkFTNNietvbErddfmFbu5 PBzQxixTBJ4VAa9ytbAyLVf5kwRDXCYh+u87n0tUZTL3Pmf6RU3hOGNYL4b3BEhJ4nuf Zf3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=pbKTa64ww9zf2YjQDVJFvTEv+LvOGCj/fGrZioGjwnM=; b=MrCLOBNCE2t85OI/bKONkqbiOysBsOpHfdVE1qzK1Gm6AjqLBWk6vFpB4pX0A46W77 cA5e/v+rx5kmXdkVtrP2J2VedLjcgilJwesK+2plVs0vCzHv8Q23H3cbVo5ooFoeHwaa K5b8lVqkTFCh4lbrUKEYfrHXHNs+Z08xt3Rl9m4GqWYgj/ve3GFHchklSrRpI3NQ/vMJ q9j8G8/LD2bN6HLblzM8UfePAkAvihochvCh4ae03ljd2rEEC5gW0tD4Fo2UKdn9Y5Lk 2MN1my04lQaMuifYflfqk2MDLqygKnSdG/4jh9OtQDdFEBFOiyi9mG3ByBRTqmwkli2t Y8WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b="TwT/sYEO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gp20-20020a17090adf1400b0020b0b8df3d2si3583315pjb.57.2022.11.18.10.23.09; Fri, 18 Nov 2022 10:23:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b="TwT/sYEO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242653AbiKRSWW (ORCPT + 99 others); Fri, 18 Nov 2022 13:22:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242658AbiKRSV7 (ORCPT ); Fri, 18 Nov 2022 13:21:59 -0500 Received: from mail-4319.protonmail.ch (mail-4319.protonmail.ch [185.70.43.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7638E922D7; Fri, 18 Nov 2022 10:21:55 -0800 (PST) Date: Fri, 18 Nov 2022 18:21:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1668795713; x=1669054913; bh=pbKTa64ww9zf2YjQDVJFvTEv+LvOGCj/fGrZioGjwnM=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=TwT/sYEOpDbDsX8Nr6x6hyvqKYFrnxnVlSH13Oynr7KYbR6Fg29S2qwhKEUjG5jqV QXhyCLx7R2Xg2YF4HaA6HdlND3j9TVGOoAAIj6zSzbd3nG3qPbNwGHxTbuL7y21AXK zki3z7GVHiH2kQLsCA2iKqzM5tyw3fhhy1/NBm9thn8nA39J9+pPpcOXB6RyG1Hnj1 TtA3dNnXQ+xbkw8aE36SRqrWcEUGI1uwBsKtIF3ZYYiqPQHrurqloRvYU/w3Fj3mJU mxQV8r3W4QyPTkL3+Sb2hl44CLQb/TVXd5vMVjHzz6gRe8MmRkq56kNSfarUHpPwuv p/0pr1DM63NMg== To: linux-kernel@vger.kernel.org From: "Lin, Meng-Bo" Cc: Markuss Broks , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Henrik Rydberg , Stephan Gerhold , Nikita Travkin , linux-input@vger.kernel.org, devicetree@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [PATCH v2 3/3] input/touchscreen: imagis: Add supports for Imagis IST3038 Message-ID: <20221118182103.3405-4-linmengbo0689@protonmail.com> In-Reply-To: <20221118182103.3405-1-linmengbo0689@protonmail.com> References: <20221118182103.3405-1-linmengbo0689@protonmail.com> Feedback-ID: 40467236:user:proton MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749859228021035209?= X-GMAIL-MSGID: =?utf-8?q?1749859228021035209?= From: Markuss Broks Imagis IST3038 is another variant of Imagis IST3038 IC, which has a different register interface from IST3038C (possibly firmware defined). This should also work for IST3044B (though untested), however other variants using this interface/protocol(IST3026, IST3032, IST3026B, IST3032B) have a different format for coordinates, and they'd need additional effort to be supported by this driver. Signed-off-by: Markuss Broks [Use IST3038C_REG_CHIPID_BASE] Signed-off-by: Lin, Meng-Bo Reviewed-by: Mattijs Korpershoek --- drivers/input/touchscreen/imagis.c | 62 ++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/drivers/input/touchscreen/imagis.c b/drivers/input/touchscreen/imagis.c index b667914a44f1..eb3b0684817f 100644 --- a/drivers/input/touchscreen/imagis.c +++ b/drivers/input/touchscreen/imagis.c @@ -13,7 +13,8 @@ #define IST3038C_HIB_ACCESS (0x800B << 16) #define IST3038C_DIRECT_ACCESS BIT(31) -#define IST3038C_REG_CHIPID 0x40001000 +#define IST3038C_REG_CHIPID_BASE 0x40001000 +#define IST3038C_REG_CHIPID(base) (base | IST3038C_DIRECT_ACCESS) #define IST3038C_REG_HIB_BASE 0x30000100 #define IST3038C_REG_TOUCH_STATUS (IST3038C_REG_HIB_BASE | IST3038C_HIB_ACCESS) #define IST3038C_REG_TOUCH_COORD (IST3038C_REG_HIB_BASE | IST3038C_HIB_ACCESS | 0x8) @@ -31,8 +32,24 @@ #define IST3038C_FINGER_COUNT_SHIFT 12 #define IST3038C_FINGER_STATUS_MASK GENMASK(9, 0) +#define IST30XX_REG_STATUS 0x20 +#define IST30XXB_REG_CHIPID_BASE 0x40000000 +#define IST30XX_WHOAMI 0x30003000 +#define IST30XXA_WHOAMI 0x300a300a +#define IST30XXB_WHOAMI 0x300b300b +#define IST3038_WHOAMI 0x30383038 + +struct imagis_properties { + unsigned int interrupt_msg_cmd; + unsigned int touch_coord_cmd; + unsigned int chipid_base; + unsigned int whoami_val; + bool protocol_b; +}; + struct imagis_ts { struct i2c_client *client; + const struct imagis_properties *tdata; struct input_dev *input_dev; struct touchscreen_properties prop; struct regulator_bulk_data supplies[2]; @@ -84,8 +101,7 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id) int i; int error; - error = imagis_i2c_read_reg(ts, IST3038C_REG_INTR_MESSAGE, - &intr_message); + error = imagis_i2c_read_reg(ts, ts->tdata->interrupt_msg_cmd, &intr_message); if (error) { dev_err(&ts->client->dev, "failed to read the interrupt message: %d\n", error); @@ -104,9 +120,13 @@ static irqreturn_t imagis_interrupt(int irq, void *dev_id) finger_pressed = intr_message & IST3038C_FINGER_STATUS_MASK; for (i = 0; i < finger_count; i++) { - error = imagis_i2c_read_reg(ts, - IST3038C_REG_TOUCH_COORD + (i * 4), - &finger_status); + if (ts->tdata->protocol_b) + error = imagis_i2c_read_reg(ts, + ts->tdata->touch_coord_cmd, &finger_status); + else + error = imagis_i2c_read_reg(ts, + ts->tdata->touch_coord_cmd + (i * 4), + &finger_status); if (error) { dev_err(&ts->client->dev, "failed to read coordinates for finger %d: %d\n", @@ -261,6 +281,12 @@ static int imagis_probe(struct i2c_client *i2c) ts->client = i2c; + ts->tdata = device_get_match_data(dev); + if (!ts->tdata) { + dev_err(dev, "missing chip data\n"); + return -EINVAL; + } + error = imagis_init_regulators(ts); if (error) { dev_err(dev, "regulator init error: %d\n", error); @@ -279,15 +305,13 @@ static int imagis_probe(struct i2c_client *i2c) return error; } - error = imagis_i2c_read_reg(ts, - IST3038C_REG_CHIPID | IST3038C_DIRECT_ACCESS, - &chip_id); + error = imagis_i2c_read_reg(ts, IST3038C_REG_CHIPID(ts->tdata->chipid_base), &chip_id); if (error) { dev_err(dev, "chip ID read failure: %d\n", error); return error; } - if (chip_id != IST3038C_WHOAMI) { + if (chip_id != ts->tdata->whoami_val) { dev_err(dev, "unknown chip ID: 0x%x\n", chip_id); return -EINVAL; } @@ -343,9 +367,25 @@ static int __maybe_unused imagis_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(imagis_pm_ops, imagis_suspend, imagis_resume); +static const struct imagis_properties imagis_3038_data = { + .interrupt_msg_cmd = IST30XX_REG_STATUS, + .touch_coord_cmd = IST30XX_REG_STATUS, + .chipid_base = IST30XXB_REG_CHIPID_BASE, + .whoami_val = IST3038_WHOAMI, + .protocol_b = true, +}; + +static const struct imagis_properties imagis_3038c_data = { + .interrupt_msg_cmd = IST3038C_REG_INTR_MESSAGE, + .touch_coord_cmd = IST3038C_REG_TOUCH_COORD, + .chipid_base = IST3038C_REG_CHIPID_BASE, + .whoami_val = IST3038C_WHOAMI, +}; + #ifdef CONFIG_OF static const struct of_device_id imagis_of_match[] = { - { .compatible = "imagis,ist3038c", }, + { .compatible = "imagis,ist3038", .data = &imagis_3038_data }, + { .compatible = "imagis,ist3038c", .data = &imagis_3038c_data }, { }, }; MODULE_DEVICE_TABLE(of, imagis_of_match);