From patchwork Sun Apr 10 12:00:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 559559 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 92553C433EF for ; Sun, 10 Apr 2022 12:03:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235668AbiDJMFQ (ORCPT ); Sun, 10 Apr 2022 08:05:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbiDJMFQ (ORCPT ); Sun, 10 Apr 2022 08:05:16 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99CE3515A3 for ; Sun, 10 Apr 2022 05:03:05 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id o16so10989425ljp.3 for ; Sun, 10 Apr 2022 05:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lzK5d2lY8VIogMRp4Vbt/no5kR/b2VMZcJXJLKKMdRg=; b=IRNqNpBt3n6AMPapGV/3wMTwWcEE5UcsvNi43toOSopVRj0gU49PWiYv6Lhnk/XD5X zuKnUomRc+yz4m5NWHgWyKMqTyi5KsAGdg2XPVW6M1iSmtm5ecRGbZvjUAquvSDkr5eg /xDXbBBYAbx8x5TAaeoaXyDPJ9QSUh6c7urk8GRbNHytIfLvEz018z5uuGns6w7YkFa1 ONu8xqc1ZKayOOP4Sv2UneJy4l/7dpDQWDXtySIcp8FSauD0KNDWpHyz2nrSpuXhl8Ie 0rw4CIsxKKRFAnsMH7gkIlqfcpYhlvzdDEgNT4fFKVtJrVJScC0GrZmgpfZSOngs0ZGS kpBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=lzK5d2lY8VIogMRp4Vbt/no5kR/b2VMZcJXJLKKMdRg=; b=xOm37hkgFm8fVJJN2UqfKnKd/aHHAPNIUnuvYusxCQWnk/sJmSXXX3ICd/q/zA8Do5 /2KmQzN+NA+XpNY9zbfUvDDwFwtJCicN/SiP762kNPVE+toDac2vgFiGXTfGjjOXiSwD XKvKHkxsbIQ+e8ftBaz1WOd38i4xqhUS6E+225+3ZPtyyOyuOTI4/CqLc0Wiip4jiQWs U86dfW05B8vc49yJn1MZ3xECeIteDKiJ/PWcXgCx8pbd/7aZN+8qzpHfX/LG24rznxfu Y1Fk4nwrP5EwDuCYjcE56uyA+yHsksbJ3xyWRR74lwcCzTIMnw9IHItzby6PDSX2CBpt t18w== X-Gm-Message-State: AOAM532OQyeo8VC4/b4fJNB97Zhca5O0X2iGE+BRCnb7ykQpq/IdtSD8 aF6bg6n6wCWlAHLZ+jpKogzwmA== X-Google-Smtp-Source: ABdhPJwXT1tH0UgUs2X4ONgLS0+3Hpja7xrcULfUOky5WlgegLMdQmrMO4qwSUTQSQJf9dPdFgKeYA== X-Received: by 2002:a2e:9348:0:b0:249:7117:b7ad with SMTP id m8-20020a2e9348000000b002497117b7admr16860731ljh.85.1649592183508; Sun, 10 Apr 2022 05:03:03 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id s10-20020a19ad4a000000b0044826a25a2esm2992216lfd.292.2022.04.10.05.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 05:03:02 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Nikita Travkin , Michael Srba , Linus Walleij Subject: [PATCH 1/5] Input: zinitix - Helper dev variable in probe() Date: Sun, 10 Apr 2022 14:00:55 +0200 Message-Id: <20220410120059.2583849-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Create a helper variable struct device *dev in probe() to make the code more compact and easier to read. Signed-off-by: Linus Walleij --- drivers/input/touchscreen/zinitix.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c index 8bd03278ad9a..cd13075ae3ab 100644 --- a/drivers/input/touchscreen/zinitix.c +++ b/drivers/input/touchscreen/zinitix.c @@ -503,15 +503,16 @@ static int zinitix_init_input_dev(struct bt541_ts_data *bt541) static int zinitix_ts_probe(struct i2c_client *client) { struct bt541_ts_data *bt541; + struct device *dev = &client->dev; int error; if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - dev_err(&client->dev, + dev_err(dev, "Failed to assert adapter's support for plain I2C.\n"); return -ENXIO; } - bt541 = devm_kzalloc(&client->dev, sizeof(*bt541), GFP_KERNEL); + bt541 = devm_kzalloc(dev, sizeof(*bt541), GFP_KERNEL); if (!bt541) return -ENOMEM; @@ -520,28 +521,28 @@ static int zinitix_ts_probe(struct i2c_client *client) error = zinitix_init_regulators(bt541); if (error) { - dev_err(&client->dev, + dev_err(dev, "Failed to initialize regulators: %d\n", error); return error; } - error = devm_request_threaded_irq(&client->dev, client->irq, + error = devm_request_threaded_irq(dev, client->irq, NULL, zinitix_ts_irq_handler, IRQF_ONESHOT | IRQF_NO_AUTOEN, client->name, bt541); if (error) { - dev_err(&client->dev, "Failed to request IRQ: %d\n", error); + dev_err(dev, "Failed to request IRQ: %d\n", error); return error; } error = zinitix_init_input_dev(bt541); if (error) { - dev_err(&client->dev, + dev_err(dev, "Failed to initialize input device: %d\n", error); return error; } - error = device_property_read_u32(&client->dev, "zinitix,mode", + error = device_property_read_u32(dev, "zinitix,mode", &bt541->zinitix_mode); if (error < 0) { /* fall back to mode 2 */ @@ -553,7 +554,7 @@ static int zinitix_ts_probe(struct i2c_client *client) * If there are devices that don't support mode 2, support * for other modes (0, 1) will be needed. */ - dev_err(&client->dev, + dev_err(dev, "Malformed zinitix,mode property, must be 2 (supplied: %d)\n", bt541->zinitix_mode); return -EINVAL; From patchwork Sun Apr 10 12:00:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 559804 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 066C9C433F5 for ; Sun, 10 Apr 2022 12:03:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235725AbiDJMF3 (ORCPT ); Sun, 10 Apr 2022 08:05:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbiDJMF3 (ORCPT ); Sun, 10 Apr 2022 08:05:29 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6936F515A3 for ; Sun, 10 Apr 2022 05:03:18 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id u19so7270825ljd.11 for ; Sun, 10 Apr 2022 05:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V+q1j/OTIHZ45TDEMMRT3/8gIJnTLMHDNQ2Nn92NyME=; b=xdwjebIzYJKPx0dK2sBRCqpQQr96syrmCWHSogYEaPUG0GzUqR2HvGXfSzdoazuEm2 3blyi4lme1R8lHuBawWdH/ohaPJ3pTb+rLzBKCY3gd5UZZ5U7NjzualRU8H8yWSd9KaT cJA80rj+KDd/mvOstcwvFNrBbzS5skfnalkBMCRacoal4o5uIGoDVOpM52qskQDYRBFR A0brEZLjcOqdvrHjYGO1hAcY0oqbkQ5DlprG/cylvkYEmUKxjKIIEILhg4wg2XecGCwh AsZzHFMMldrbNfTZhYll4VyElE0e5N29bRPhpSnm+hQvarzPRlkx1JpnyeigfsrPPh98 L3gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V+q1j/OTIHZ45TDEMMRT3/8gIJnTLMHDNQ2Nn92NyME=; b=VtgnbzRrz9I/gL1uwefycvVxgCDe830gAfN5Wqp2o1CEQzJQVB5fb+bOR2+Dwvt3vD DSDMsEcBWjoY8M70YiL26pivWDLEwq68qkMC336EnDeMvCbRMceOttCLNK0EPyXWZGLc KhLc9Q76jQ5rvZicPTIwaVI6XmCFnEQrV4rvMRtleM/gmXqDNJ94IGv23v0SLdexulny SwaOhyew0nLeKTAXLeVYRSNhkiUFfnURx9KnGKNZvHgngaMdm1i86tcmBoWLBzeuperY 60Q8VM9+BpfV7W0fS94FWgsPdqIicsMHbBnd4EpK0sHYft+TLOx+Ic9fKletVT/9UIkU fKJg== X-Gm-Message-State: AOAM53149tUoJQqL+BvWJ+W3NALUVhOebyPiSbXOsEp6JsVlm1YGaPjV eFBNzsSV4pkAlFtMb0A8OPQMuQ== X-Google-Smtp-Source: ABdhPJy03EF/yESnInxHlyQVeSvg+97UiXsxhuZPBCd/RoZUs1wLXSBQe+4loQVKiHGDAeCW4zZ+uw== X-Received: by 2002:a2e:b70b:0:b0:24b:62fa:91b6 with SMTP id j11-20020a2eb70b000000b0024b62fa91b6mr362548ljo.288.1649592196484; Sun, 10 Apr 2022 05:03:16 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id s10-20020a19ad4a000000b0044826a25a2esm2992216lfd.292.2022.04.10.05.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 05:03:16 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Nikita Travkin , Michael Srba , Linus Walleij Subject: [PATCH 2/5] Input: zinitix - Add dev variable in state Date: Sun, 10 Apr 2022 14:00:56 +0200 Message-Id: <20220410120059.2583849-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220410120059.2583849-1-linus.walleij@linaro.org> References: <20220410120059.2583849-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org To avoid several steps of dereferencing the struct device from the client, add a struct device *dev pointer to the state container so we can easily get to the struct device. This makes the code more compact and easier to read. Signed-off-by: Linus Walleij --- drivers/input/touchscreen/zinitix.c | 37 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c index cd13075ae3ab..11af1264cafa 100644 --- a/drivers/input/touchscreen/zinitix.c +++ b/drivers/input/touchscreen/zinitix.c @@ -142,6 +142,7 @@ struct touch_event { struct bt541_ts_data { struct i2c_client *client; + struct device *dev; struct input_dev *input_dev; struct touchscreen_properties prop; struct regulator_bulk_data supplies[2]; @@ -198,13 +199,13 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) error = zinitix_write_cmd(client, BT541_SWRESET_CMD); if (error) { - dev_err(&client->dev, "Failed to write reset command\n"); + dev_err(bt541->dev, "Failed to write reset command\n"); return error; } error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG, 0x0); if (error) { - dev_err(&client->dev, + dev_err(bt541->dev, "Failed to reset interrupt enable flag\n"); return error; } @@ -252,7 +253,7 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) static int zinitix_init_regulators(struct bt541_ts_data *bt541) { - struct device *dev = &bt541->client->dev; + struct device *dev = bt541->dev; int error; /* @@ -286,7 +287,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541) error = zinitix_write_u16(client, 0xc000, 0x0001); if (error) { - dev_err(&client->dev, + dev_err(bt541->dev, "Failed to send power sequence(vendor cmd enable)\n"); return error; } @@ -294,7 +295,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541) error = zinitix_write_cmd(client, 0xc004); if (error) { - dev_err(&client->dev, + dev_err(bt541->dev, "Failed to send power sequence (intn clear)\n"); return error; } @@ -302,7 +303,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541) error = zinitix_write_u16(client, 0xc002, 0x0001); if (error) { - dev_err(&client->dev, + dev_err(bt541->dev, "Failed to send power sequence (nvm init)\n"); return error; } @@ -310,7 +311,7 @@ static int zinitix_send_power_on_sequence(struct bt541_ts_data *bt541) error = zinitix_write_u16(client, 0xc001, 0x0001); if (error) { - dev_err(&client->dev, + dev_err(bt541->dev, "Failed to send power sequence (program start)\n"); return error; } @@ -353,7 +354,6 @@ static void zinitix_report_finger(struct bt541_ts_data *bt541, int slot, static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler) { struct bt541_ts_data *bt541 = bt541_handler; - struct i2c_client *client = bt541->client; struct touch_event touch_event; unsigned long finger_mask; int error; @@ -364,7 +364,7 @@ static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler) error = zinitix_read_data(bt541->client, BT541_POINT_STATUS_REG, &touch_event, sizeof(struct touch_event)); if (error) { - dev_err(&client->dev, "Failed to read in touchpoint struct\n"); + dev_err(bt541->dev, "Failed to read in touchpoint struct\n"); goto out; } @@ -392,7 +392,7 @@ static int zinitix_start(struct bt541_ts_data *bt541) error = regulator_bulk_enable(ARRAY_SIZE(bt541->supplies), bt541->supplies); if (error) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Failed to enable regulators: %d\n", error); return error; } @@ -401,14 +401,14 @@ static int zinitix_start(struct bt541_ts_data *bt541) error = zinitix_send_power_on_sequence(bt541); if (error) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Error while sending power-on sequence: %d\n", error); return error; } error = zinitix_init_touch(bt541); if (error) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Error while configuring touch IC\n"); return error; } @@ -427,7 +427,7 @@ static int zinitix_stop(struct bt541_ts_data *bt541) error = regulator_bulk_disable(ARRAY_SIZE(bt541->supplies), bt541->supplies); if (error) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Failed to disable regulators: %d\n", error); return error; } @@ -454,9 +454,9 @@ static int zinitix_init_input_dev(struct bt541_ts_data *bt541) struct input_dev *input_dev; int error; - input_dev = devm_input_allocate_device(&bt541->client->dev); + input_dev = devm_input_allocate_device(bt541->dev); if (!input_dev) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Failed to allocate input device."); return -ENOMEM; } @@ -477,7 +477,7 @@ static int zinitix_init_input_dev(struct bt541_ts_data *bt541) touchscreen_parse_properties(input_dev, true, &bt541->prop); if (!bt541->prop.max_x || !bt541->prop.max_y) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Touchscreen-size-x and/or touchscreen-size-y not set in dts\n"); return -EINVAL; } @@ -485,14 +485,14 @@ static int zinitix_init_input_dev(struct bt541_ts_data *bt541) error = input_mt_init_slots(input_dev, MAX_SUPPORTED_FINGER_NUM, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); if (error) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Failed to initialize MT slots: %d", error); return error; } error = input_register_device(input_dev); if (error) { - dev_err(&bt541->client->dev, + dev_err(bt541->dev, "Failed to register input device: %d", error); return error; } @@ -517,6 +517,7 @@ static int zinitix_ts_probe(struct i2c_client *client) return -ENOMEM; bt541->client = client; + bt541->dev = dev; i2c_set_clientdata(client, bt541); error = zinitix_init_regulators(bt541); From patchwork Sun Apr 10 12:00:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 559558 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 05086C433EF for ; Sun, 10 Apr 2022 12:03:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238648AbiDJMFe (ORCPT ); Sun, 10 Apr 2022 08:05:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236345AbiDJMFa (ORCPT ); Sun, 10 Apr 2022 08:05:30 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A796C515A7 for ; Sun, 10 Apr 2022 05:03:19 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id r2so1534376ljd.10 for ; Sun, 10 Apr 2022 05:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z+hX7ZywiI6nnWAjek7vTxivDNNO4zg0+bjY8RT7gU4=; b=NjU5IGzBceY39DxMTrBqmYVlEuPiPVK+4AlPb0qkSAFHBoxkET2/DpNUT+MesZx0LB yAWi7cMX/tTqarDAwTB/EjcttM3j73EV/phL6OXBW5ZDsUMhBYi6BgnrXZGHorYf68Jb TeoXGsCRFpEadDc77zVDSccvTAvPDQGD+/5MWtsYKXa+aj19TOXdIxlqGhj6HWn2JXQ1 Dh9IRXM584GbyJt6spUT3cE9yEtaZ+Or9EkMTrYUw7L7Qs+LojTQvzoaTPafuqRJG5FZ 53rUbTSmm17Jh2lhreQK6f0HSKWCHwsDR1kM3Vy70T9NC4SqfQoX0syzDGXOIgFu9Vgc BK/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z+hX7ZywiI6nnWAjek7vTxivDNNO4zg0+bjY8RT7gU4=; b=Iglf1m738SGZnnmNqXSjORW9h87TIxX7I0wKlsSpf6/nyJRob+tCv47pmJnl3yXXsp 23FYSkBXyHtZ6+M9oaOqXDVg+L+SNA0Do+ftq4IQNBSGEy8gAONMKy2bzWJd51/T3xDt 86cTcsrofPi2zJ3q5RSz4BSRjOHujzIUkHhubEuDakQPtGKkLQWYcFjlFC92URWOYEjp VxSObEIIPzvgWw5LKPSFC4U2efMUCRj0hM+8WLuMvdFLVjgmi2iq6kw4L/JO9yLxnyja Q8Ri3FSCl6jTlRo4Rirel2yTiyzjFwPQOU65l4/oU/pZRGxdC5diQRtC9oW54bL1MSQA I8HQ== X-Gm-Message-State: AOAM533mKjYRXGhKNhE8QnQCTNNaYfmmE8MgOCbTXdRDLucFB8J/Wbso 79oyTSn4chcuMN79dH8P6S6AFA== X-Google-Smtp-Source: ABdhPJzLkI3aBdeP9HK7BjiLQ1/7oLBz10JaOjqRqYIN6dUlFt7Bw+3IGYEJOF8B4vYHDxo0Ugq0MQ== X-Received: by 2002:a2e:b6c3:0:b0:249:9b61:656f with SMTP id m3-20020a2eb6c3000000b002499b61656fmr17173390ljo.266.1649592197847; Sun, 10 Apr 2022 05:03:17 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id s10-20020a19ad4a000000b0044826a25a2esm2992216lfd.292.2022.04.10.05.03.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 05:03:17 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Nikita Travkin , Michael Srba , Linus Walleij Subject: [PATCH 3/5] Input: zinitix - Rename defines ZINITIX_* Date: Sun, 10 Apr 2022 14:00:57 +0200 Message-Id: <20220410120059.2583849-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220410120059.2583849-1-linus.walleij@linaro.org> References: <20220410120059.2583849-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The defines are sometimes named BT541_* and sometimes ZINITIX_*, name them all ZINITIX_* because they certainly apply to a lot more touchscreens than the BT541. Signed-off-by: Linus Walleij --- drivers/input/touchscreen/zinitix.c | 112 ++++++++++++++-------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c index 11af1264cafa..f89dea49cf1f 100644 --- a/drivers/input/touchscreen/zinitix.c +++ b/drivers/input/touchscreen/zinitix.c @@ -15,75 +15,75 @@ /* Register Map */ -#define BT541_SWRESET_CMD 0x0000 -#define BT541_WAKEUP_CMD 0x0001 +#define ZINITIX_SWRESET_CMD 0x0000 +#define ZINITIX_WAKEUP_CMD 0x0001 -#define BT541_IDLE_CMD 0x0004 -#define BT541_SLEEP_CMD 0x0005 +#define ZINITIX_IDLE_CMD 0x0004 +#define ZINITIX_SLEEP_CMD 0x0005 -#define BT541_CLEAR_INT_STATUS_CMD 0x0003 -#define BT541_CALIBRATE_CMD 0x0006 -#define BT541_SAVE_STATUS_CMD 0x0007 -#define BT541_SAVE_CALIBRATION_CMD 0x0008 -#define BT541_RECALL_FACTORY_CMD 0x000f +#define ZINITIX_CLEAR_INT_STATUS_CMD 0x0003 +#define ZINITIX_CALIBRATE_CMD 0x0006 +#define ZINITIX_SAVE_STATUS_CMD 0x0007 +#define ZINITIX_SAVE_CALIBRATION_CMD 0x0008 +#define ZINITIX_RECALL_FACTORY_CMD 0x000f -#define BT541_THRESHOLD 0x0020 +#define ZINITIX_THRESHOLD 0x0020 -#define BT541_LARGE_PALM_REJECT_AREA_TH 0x003F +#define ZINITIX_LARGE_PALM_REJECT_AREA_TH 0x003F -#define BT541_DEBUG_REG 0x0115 /* 0~7 */ +#define ZINITIX_DEBUG_REG 0x0115 /* 0~7 */ -#define BT541_TOUCH_MODE 0x0010 -#define BT541_CHIP_REVISION 0x0011 -#define BT541_FIRMWARE_VERSION 0x0012 +#define ZINITIX_TOUCH_MODE 0x0010 +#define ZINITIX_CHIP_REVISION 0x0011 +#define ZINITIX_FIRMWARE_VERSION 0x0012 #define ZINITIX_USB_DETECT 0x116 -#define BT541_MINOR_FW_VERSION 0x0121 +#define ZINITIX_MINOR_FW_VERSION 0x0121 -#define BT541_VENDOR_ID 0x001C -#define BT541_HW_ID 0x0014 +#define ZINITIX_VENDOR_ID 0x001C +#define ZINITIX_HW_ID 0x0014 -#define BT541_DATA_VERSION_REG 0x0013 -#define BT541_SUPPORTED_FINGER_NUM 0x0015 -#define BT541_EEPROM_INFO 0x0018 -#define BT541_INITIAL_TOUCH_MODE 0x0019 +#define ZINITIX_DATA_VERSION_REG 0x0013 +#define ZINITIX_SUPPORTED_FINGER_NUM 0x0015 +#define ZINITIX_EEPROM_INFO 0x0018 +#define ZINITIX_INITIAL_TOUCH_MODE 0x0019 -#define BT541_TOTAL_NUMBER_OF_X 0x0060 -#define BT541_TOTAL_NUMBER_OF_Y 0x0061 +#define ZINITIX_TOTAL_NUMBER_OF_X 0x0060 +#define ZINITIX_TOTAL_NUMBER_OF_Y 0x0061 -#define BT541_DELAY_RAW_FOR_HOST 0x007f +#define ZINITIX_DELAY_RAW_FOR_HOST 0x007f -#define BT541_BUTTON_SUPPORTED_NUM 0x00B0 -#define BT541_BUTTON_SENSITIVITY 0x00B2 -#define BT541_DUMMY_BUTTON_SENSITIVITY 0X00C8 +#define ZINITIX_BUTTON_SUPPORTED_NUM 0x00B0 +#define ZINITIX_BUTTON_SENSITIVITY 0x00B2 +#define ZINITIX_DUMMY_BUTTON_SENSITIVITY 0X00C8 -#define BT541_X_RESOLUTION 0x00C0 -#define BT541_Y_RESOLUTION 0x00C1 +#define ZINITIX_X_RESOLUTION 0x00C0 +#define ZINITIX_Y_RESOLUTION 0x00C1 -#define BT541_POINT_STATUS_REG 0x0080 -#define BT541_ICON_STATUS_REG 0x00AA +#define ZINITIX_POINT_STATUS_REG 0x0080 +#define ZINITIX_ICON_STATUS_REG 0x00AA -#define BT541_POINT_COORD_REG (BT541_POINT_STATUS_REG + 2) +#define ZINITIX_POINT_COORD_REG (ZINITIX_POINT_STATUS_REG + 2) -#define BT541_AFE_FREQUENCY 0x0100 -#define BT541_DND_N_COUNT 0x0122 -#define BT541_DND_U_COUNT 0x0135 +#define ZINITIX_AFE_FREQUENCY 0x0100 +#define ZINITIX_DND_N_COUNT 0x0122 +#define ZINITIX_DND_U_COUNT 0x0135 -#define BT541_RAWDATA_REG 0x0200 +#define ZINITIX_RAWDATA_REG 0x0200 -#define BT541_EEPROM_INFO_REG 0x0018 +#define ZINITIX_EEPROM_INFO_REG 0x0018 -#define BT541_INT_ENABLE_FLAG 0x00f0 -#define BT541_PERIODICAL_INTERRUPT_INTERVAL 0x00f1 +#define ZINITIX_INT_ENABLE_FLAG 0x00f0 +#define ZINITIX_PERIODICAL_INTERRUPT_INTERVAL 0x00f1 -#define BT541_BTN_WIDTH 0x016d +#define ZINITIX_BTN_WIDTH 0x016d -#define BT541_CHECKSUM_RESULT 0x012c +#define ZINITIX_CHECKSUM_RESULT 0x012c -#define BT541_INIT_FLASH 0x01d0 -#define BT541_WRITE_FLASH 0x01d1 -#define BT541_READ_FLASH 0x01d2 +#define ZINITIX_INIT_FLASH 0x01d0 +#define ZINITIX_WRITE_FLASH 0x01d1 +#define ZINITIX_READ_FLASH 0x01d2 #define ZINITIX_INTERNAL_FLAG_02 0x011e #define ZINITIX_INTERNAL_FLAG_03 0x011f @@ -197,13 +197,13 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) int i; int error; - error = zinitix_write_cmd(client, BT541_SWRESET_CMD); + error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); if (error) { dev_err(bt541->dev, "Failed to write reset command\n"); return error; } - error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG, 0x0); + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 0x0); if (error) { dev_err(bt541->dev, "Failed to reset interrupt enable flag\n"); @@ -211,32 +211,32 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) } /* initialize */ - error = zinitix_write_u16(client, BT541_X_RESOLUTION, + error = zinitix_write_u16(client, ZINITIX_X_RESOLUTION, bt541->prop.max_x); if (error) return error; - error = zinitix_write_u16(client, BT541_Y_RESOLUTION, + error = zinitix_write_u16(client, ZINITIX_Y_RESOLUTION, bt541->prop.max_y); if (error) return error; - error = zinitix_write_u16(client, BT541_SUPPORTED_FINGER_NUM, + error = zinitix_write_u16(client, ZINITIX_SUPPORTED_FINGER_NUM, MAX_SUPPORTED_FINGER_NUM); if (error) return error; - error = zinitix_write_u16(client, BT541_INITIAL_TOUCH_MODE, + error = zinitix_write_u16(client, ZINITIX_INITIAL_TOUCH_MODE, bt541->zinitix_mode); if (error) return error; - error = zinitix_write_u16(client, BT541_TOUCH_MODE, + error = zinitix_write_u16(client, ZINITIX_TOUCH_MODE, bt541->zinitix_mode); if (error) return error; - error = zinitix_write_u16(client, BT541_INT_ENABLE_FLAG, + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE | BIT_UP); if (error) @@ -244,7 +244,7 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) /* clear queue */ for (i = 0; i < 10; i++) { - zinitix_write_cmd(client, BT541_CLEAR_INT_STATUS_CMD); + zinitix_write_cmd(client, ZINITIX_CLEAR_INT_STATUS_CMD); udelay(10); } @@ -361,7 +361,7 @@ static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler) memset(&touch_event, 0, sizeof(struct touch_event)); - error = zinitix_read_data(bt541->client, BT541_POINT_STATUS_REG, + error = zinitix_read_data(bt541->client, ZINITIX_POINT_STATUS_REG, &touch_event, sizeof(struct touch_event)); if (error) { dev_err(bt541->dev, "Failed to read in touchpoint struct\n"); @@ -381,7 +381,7 @@ static irqreturn_t zinitix_ts_irq_handler(int irq, void *bt541_handler) input_sync(bt541->input_dev); out: - zinitix_write_cmd(bt541->client, BT541_CLEAR_INT_STATUS_CMD); + zinitix_write_cmd(bt541->client, ZINITIX_CLEAR_INT_STATUS_CMD); return IRQ_HANDLED; } From patchwork Sun Apr 10 12:00:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 559803 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 D02CCC433FE for ; Sun, 10 Apr 2022 12:03:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236345AbiDJMFf (ORCPT ); Sun, 10 Apr 2022 08:05:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbiDJMFc (ORCPT ); Sun, 10 Apr 2022 08:05:32 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC83F515A3 for ; Sun, 10 Apr 2022 05:03:20 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id r18so1219806ljp.0 for ; Sun, 10 Apr 2022 05:03:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dsoR6g73eC63SWlGERr29fTr25y7gIiBYQZuhqPojTM=; b=ULTA1zA7N6zs0820i6Cfi5VJ4dci32sGLNoPrSHkKSLBLQf86IhIOXpBTGLXcvnZUC L/pOSr/+QyMaTaGQiLu0tDoapcaoqkJmSsvmTqCwein91neggkx/NFuH/q2Q9H9oUh4o yiJMPw8/0dIsm4aXl/ecTcoFjTba507ZtDRjQ/Tyn52wdjt+urbb/XL9TA65BGV3eXei +SYCmX5pOIdA4caiHWGW8s8D5EKuhMrxalVTveNT7fI+klTe6sfOnxdyNFjipXtuN4Ek LvdgfUWmlzEF1df2msArl8GeGWtNSPdwyQdVSh1q29xzJROsGg2kJjXyqcEsG+I4Dxc2 YWCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dsoR6g73eC63SWlGERr29fTr25y7gIiBYQZuhqPojTM=; b=ymBat253d2Jr1FNvMLEsDXR0HGKDENe2hEK4LwTBGXMq8qrK69Mtra8Nr+pcr0YlsP 14LP1g2D54cLXFBYoJBvjk2ED8RSLjqnDIDqcoW/y9QQcI+tiTt/EO58OlN8WMRc1l5I qqU9gwMcHYzBPeR4RtxbZ64XSopyVBrC/ZNSCYndG8O/tcDOXfLZGbee2UVyUigPCgnv XT0+drxJ8OQ0ls2ZF8/vj0h8ctudpB6f7ErY1RuzXdGUNKrlRxxp8wWibeWiqQuK0fyD /Z78Xd4gmC3IXxrNjTvghursypMQiY3+HiGxuaKvP8RVdP5qFR4MNXnxHaP70PbaeCM0 brPA== X-Gm-Message-State: AOAM5326jpR9raAiKSiAIv8vpwkB0u1bCHFnTSoXRZ/d2m/qdyzACpk+ 4oX4hzIv/+AxS/WjIh+crYKNdA== X-Google-Smtp-Source: ABdhPJyGAaPkcdIl8TJnXHt9leN58ZckkVn56QLGF98Rtb62Jb3tqMGvNb3GfN4RNBewcrYAxwc37g== X-Received: by 2002:a2e:54e:0:b0:24b:58aa:735f with SMTP id 75-20020a2e054e000000b0024b58aa735fmr4465833ljf.530.1649592199244; Sun, 10 Apr 2022 05:03:19 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id s10-20020a19ad4a000000b0044826a25a2esm2992216lfd.292.2022.04.10.05.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 05:03:18 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Nikita Travkin , Michael Srba , Linus Walleij Subject: [PATCH 4/5] Input: zinitix - Read and cache device version numbers Date: Sun, 10 Apr 2022 14:00:58 +0200 Message-Id: <20220410120059.2583849-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220410120059.2583849-1-linus.walleij@linaro.org> References: <20220410120059.2583849-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The chip hardware revision, firmware version and regdata revision is useful to know, so read this out and print it the first time we open the device. Example output from BT404: Zinitix-TS 3-0020: chip revision 4040 firmware version 0088 regdata version 0004 Signed-off-by: Linus Walleij --- drivers/input/touchscreen/zinitix.c | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c index f89dea49cf1f..ea807b972f26 100644 --- a/drivers/input/touchscreen/zinitix.c +++ b/drivers/input/touchscreen/zinitix.c @@ -35,6 +35,9 @@ #define ZINITIX_TOUCH_MODE 0x0010 #define ZINITIX_CHIP_REVISION 0x0011 +#define ZINITIX_CHIP_BT404 0x4040 +#define ZINITIX_CHIP_BT532 0x5320 +#define ZINITIX_CHIP_BT541 0x5410 #define ZINITIX_FIRMWARE_VERSION 0x0012 #define ZINITIX_USB_DETECT 0x116 @@ -147,6 +150,9 @@ struct bt541_ts_data { struct touchscreen_properties prop; struct regulator_bulk_data supplies[2]; u32 zinitix_mode; + u16 chip_revision; + u16 firmware_version; + u16 regdata_version; }; static int zinitix_read_data(struct i2c_client *client, @@ -191,11 +197,24 @@ static int zinitix_write_cmd(struct i2c_client *client, u16 reg) return 0; } +static u16 zinitix_get_u16_reg(struct bt541_ts_data *bt541, u16 vreg) +{ + struct i2c_client *client = bt541->client; + int error; + __le16 val; + + error = zinitix_read_data(client, vreg, (void *)&val, 2); + if (error) + return U8_MAX; + return le16_to_cpu(val); +} + static int zinitix_init_touch(struct bt541_ts_data *bt541) { struct i2c_client *client = bt541->client; int i; int error; + static bool read_static = false; error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); if (error) { @@ -203,6 +222,24 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) return error; } + /* + * Read and cache the chip revision and firmware version the first time + * we get here. + */ + if (!read_static) { + bt541->chip_revision = zinitix_get_u16_reg(bt541, + ZINITIX_CHIP_REVISION); + bt541->firmware_version = zinitix_get_u16_reg(bt541, + ZINITIX_FIRMWARE_VERSION); + bt541->regdata_version = zinitix_get_u16_reg(bt541, + ZINITIX_DATA_VERSION_REG); + dev_info(bt541->dev, + "chip revision %04x firmware version %04x regdata version %04x\n", + bt541->chip_revision, bt541->firmware_version, + bt541->regdata_version); + read_static = true; + } + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 0x0); if (error) { dev_err(bt541->dev, From patchwork Sun Apr 10 12:00:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 559557 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 E5FD3C4332F for ; Sun, 10 Apr 2022 12:03:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230125AbiDJMFg (ORCPT ); Sun, 10 Apr 2022 08:05:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238644AbiDJMFd (ORCPT ); Sun, 10 Apr 2022 08:05:33 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76DF7515A8 for ; Sun, 10 Apr 2022 05:03:22 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id x17so13000508lfa.10 for ; Sun, 10 Apr 2022 05:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p63T0wI5Y0SynUtb2tKtw6BTlbvTq7jOTGTQDwjUp7k=; b=a5ttDyLSTLXhL88n9LwXkFnwQ73rZlcfxxlWOYZtqcfaFfpjS3xPmhQF+kDnOWrcf6 YYOjEc681OhngudXk5e/a9JUuD73Q1j3DK8W1zXz/NduDGsZEJlu7qOefm1JEE2XyEez LkrF2r27FVtHADzoeEGkUk6R1AalEY7APRcm+HcTtG2+mfYjonttwPfFkOJskkZwjYsa vBEiOHvy3Dhmm5windjh7PmtLyQyxZvwsKzoLzg3MDnxGjCpqaAnTHFGGje4kE99FSYG pz+7eRoVxyAkRF0EI2c6lG9m/4xiVb7kfCAlNYci/gqD5mz24aqUB+FR6I5RWVKHZx7w vt2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p63T0wI5Y0SynUtb2tKtw6BTlbvTq7jOTGTQDwjUp7k=; b=B57kqeElQcIG12wdWbdgbYpcSjEjTi5aamXRaL1Ug32B9YsCBL9Th9U9KUzOivbaR7 sOH+Fs+XwFrCajRN5H0LkNJXWEG73RnHKvIy/Wrue1ofdLpi4RlKlkAfZagpe8NN7TEk hOSYKtVrMwiZBsZuM9eQ+mpPs8SEyZoUTNSJFC5hy5licO3sX/Q/ltZPsPv5ugcBHuM7 DFTKrd0xLBnXj18VYh5fe8PUFFJBngMWmx9IMPvPa4JUnXb49wsF7ad94ofQJVpIgWXI 3To4LG1OM8jtj9eEakkhQAuvB/5KBKE0ufABDwqq9mNB+J/u/P7lHczt+8nvTQQPKOhB MDug== X-Gm-Message-State: AOAM53342Lno93S8hzv1VsmgTnFwuutTmjZxtCIb0pe3OeiuCN76UmOo 7eM27gXUVbNRrr+qMH70PXrIkg== X-Google-Smtp-Source: ABdhPJxVm9OTqYdnXbiKAU4Oigj/9C7d4pvkiPgDsgnbXDlzkk7wx0SLIzwfDwshLK9FbmSsZ1vlQA== X-Received: by 2002:a05:6512:2313:b0:46b:a1e2:854a with SMTP id o19-20020a056512231300b0046ba1e2854amr1778517lfu.55.1649592200678; Sun, 10 Apr 2022 05:03:20 -0700 (PDT) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id s10-20020a19ad4a000000b0044826a25a2esm2992216lfd.292.2022.04.10.05.03.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 05:03:20 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Nikita Travkin , Michael Srba , Linus Walleij Subject: [PATCH 5/5] Input: zinitix - Support calibration Date: Sun, 10 Apr 2022 14:00:59 +0200 Message-Id: <20220410120059.2583849-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220410120059.2583849-1-linus.walleij@linaro.org> References: <20220410120059.2583849-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Support both hardware and software calibration on the Zinitix touchscreens. This is lifted from the vendor driver but rewritten to use the chip revision number in the hardware instead of compile-time defines. Use defines for the new "calibration mode" and add a new define for the default touchpoint mode. The registers for reading the EEPROM status actually differs between BT5x2 and BT4x3+ so create very unique defines for those registers and use a register variable in the state to keep track of the right one to use. Signed-off-by: Linus Walleij --- drivers/input/touchscreen/zinitix.c | 138 ++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 6 deletions(-) diff --git a/drivers/input/touchscreen/zinitix.c b/drivers/input/touchscreen/zinitix.c index ea807b972f26..440ffc7c9b32 100644 --- a/drivers/input/touchscreen/zinitix.c +++ b/drivers/input/touchscreen/zinitix.c @@ -34,6 +34,8 @@ #define ZINITIX_DEBUG_REG 0x0115 /* 0~7 */ #define ZINITIX_TOUCH_MODE 0x0010 +#define ZINITIX_MODE_TOUCH_POINT 0x02 +#define ZINITIX_MODE_CALIBRATION 0x07 #define ZINITIX_CHIP_REVISION 0x0011 #define ZINITIX_CHIP_BT404 0x4040 #define ZINITIX_CHIP_BT532 0x5320 @@ -49,7 +51,11 @@ #define ZINITIX_DATA_VERSION_REG 0x0013 #define ZINITIX_SUPPORTED_FINGER_NUM 0x0015 -#define ZINITIX_EEPROM_INFO 0x0018 + +#define BT4X2_EEPROM_INFO 0x0014 +#define BT4X3_EEPROM_INFO 0x0018 +#define ZINITIX_EEPROM_HW_CALIB BIT(0) + #define ZINITIX_INITIAL_TOUCH_MODE 0x0019 #define ZINITIX_TOTAL_NUMBER_OF_X 0x0060 @@ -57,6 +63,8 @@ #define ZINITIX_DELAY_RAW_FOR_HOST 0x007f +#define BT4X2_EEPROM_INFO_REG 0x00aa + #define ZINITIX_BUTTON_SUPPORTED_NUM 0x00B0 #define ZINITIX_BUTTON_SENSITIVITY 0x00B2 #define ZINITIX_DUMMY_BUTTON_SENSITIVITY 0X00C8 @@ -75,8 +83,6 @@ #define ZINITIX_RAWDATA_REG 0x0200 -#define ZINITIX_EEPROM_INFO_REG 0x0018 - #define ZINITIX_INT_ENABLE_FLAG 0x00f0 #define ZINITIX_PERIODICAL_INTERRUPT_INTERVAL 0x00f1 @@ -120,7 +126,6 @@ #define SUB_BIT_UPDATE BIT(4) #define SUB_BIT_WAIT BIT(5) -#define DEFAULT_TOUCH_POINT_MODE 2 #define MAX_SUPPORTED_FINGER_NUM 5 #define CHIP_ON_DELAY 15 // ms @@ -153,8 +158,33 @@ struct bt541_ts_data { u16 chip_revision; u16 firmware_version; u16 regdata_version; + u16 eeprom_info_reg; }; +static bool zinitix_is_4x2(struct bt541_ts_data *bt541) +{ + u16 ver; + + /* The revision is the high nybbles so shift down */ + ver = bt541->chip_revision >> 4; + /* Skip middle digit */ + ver &= 0xf0f; + + return (ver == 0x402); +} + +static bool zinitix_is_4x3_and_above(struct bt541_ts_data *bt541) +{ + u16 ver; + + /* The revision is the high nybbles so shift down */ + ver = bt541->chip_revision >> 4; + /* Skip middle digit */ + ver &= 0xf0f; + + return (ver >= 0x403); +} + static int zinitix_read_data(struct i2c_client *client, u16 reg, void *values, size_t length) { @@ -209,12 +239,92 @@ static u16 zinitix_get_u16_reg(struct bt541_ts_data *bt541, u16 vreg) return le16_to_cpu(val); } +static int zinitix_calibrate(struct bt541_ts_data *bt541) +{ + struct i2c_client *client = bt541->client; + int maxsec = 10; + int error; + u16 val; + + dev_info(bt541->dev, "HW calibration - calibrating\n"); + + error = zinitix_write_u16(client, ZINITIX_TOUCH_MODE, + ZINITIX_MODE_CALIBRATION); + if (error) + return error; + error = zinitix_write_cmd(client, ZINITIX_CALIBRATE_CMD); + if (error) + return error; + error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); + if (error) + return error; + msleep(1); + error = zinitix_write_cmd(client, ZINITIX_CLEAR_INT_STATUS_CMD); + if (error) + return error; + + /* Wait for hardware calibration to commence */ + do { + msleep(1000); + val = zinitix_get_u16_reg(bt541, bt541->eeprom_info_reg); + maxsec --; + } while ((val & ZINITIX_EEPROM_HW_CALIB) && maxsec); + + if (!maxsec) { + dev_err(bt541->dev, "timeout waiting for HW calibration\n"); + return -ETIMEDOUT; + } + + /* Get out of calibration mode */ + error = zinitix_write_u16(client, ZINITIX_TOUCH_MODE, + bt541->zinitix_mode); + if (error) + return error; + + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 0x0); + if (error) + return error; + + msleep(10); + + error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); + if (error) + return error; + + if (zinitix_is_4x3_and_above(bt541)) { + error = zinitix_write_cmd(client, ZINITIX_SAVE_CALIBRATION_CMD); + if (error) + return error; + msleep(500); + } + + if (zinitix_is_4x2(bt541)) { + error = zinitix_write_cmd(client, ZINITIX_SAVE_STATUS_CMD); + if (error) + return error; + /* Wait for fusing EEPROM */ + msleep(1000); + error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); + if (error) + return error; + } + + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 0x0); + if (error) + return error; + + dev_info(bt541->dev, "HW calibration complete\n"); + + return 0; +} + static int zinitix_init_touch(struct bt541_ts_data *bt541) { struct i2c_client *client = bt541->client; int i; int error; static bool read_static = false; + u16 val; error = zinitix_write_cmd(client, ZINITIX_SWRESET_CMD); if (error) { @@ -237,9 +347,20 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) "chip revision %04x firmware version %04x regdata version %04x\n", bt541->chip_revision, bt541->firmware_version, bt541->regdata_version); + if (zinitix_is_4x2(bt541)) + bt541->eeprom_info_reg = BT4X2_EEPROM_INFO_REG; + else + bt541->eeprom_info_reg = BT4X3_EEPROM_INFO; read_static = true; } + val = zinitix_get_u16_reg(bt541, bt541->eeprom_info_reg); + if (val & ZINITIX_EEPROM_HW_CALIB) { + error = zinitix_calibrate(bt541); + if (error) + return error; + } + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, 0x0); if (error) { dev_err(bt541->dev, @@ -273,6 +394,11 @@ static int zinitix_init_touch(struct bt541_ts_data *bt541) if (error) return error; + /* Software calibration */ + error = zinitix_write_cmd(client, ZINITIX_CALIBRATE_CMD); + if (error) + return error; + error = zinitix_write_u16(client, ZINITIX_INT_ENABLE_FLAG, BIT_PT_CNT_CHANGE | BIT_DOWN | BIT_MOVE | BIT_UP); @@ -584,10 +710,10 @@ static int zinitix_ts_probe(struct i2c_client *client) &bt541->zinitix_mode); if (error < 0) { /* fall back to mode 2 */ - bt541->zinitix_mode = DEFAULT_TOUCH_POINT_MODE; + bt541->zinitix_mode = ZINITIX_MODE_TOUCH_POINT; } - if (bt541->zinitix_mode != 2) { + if (bt541->zinitix_mode != ZINITIX_MODE_TOUCH_POINT) { /* * If there are devices that don't support mode 2, support * for other modes (0, 1) will be needed.