From patchwork Mon Jul 24 05:30:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323450 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 B1523C0015E for ; Mon, 24 Jul 2023 05:30:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbjGXFae (ORCPT ); Mon, 24 Jul 2023 01:30:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbjGXFac (ORCPT ); Mon, 24 Jul 2023 01:30:32 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A062E109; Sun, 23 Jul 2023 22:30:27 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-583d63ca1e9so13620087b3.1; Sun, 23 Jul 2023 22:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690176626; x=1690781426; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TnxapSoOoqrx/JmjeK0D4Eqy+ziHuQAnxXeq35Wg/z4=; b=Eh9w1ztROQv0GBXKw5jQboCjf5CmerGXt1srqxDtS8JJYcJgFw1XG1VECXJetgpR9M p9XlmBV1Y29iuxEdXKhptSXxy/HGSBJoMOsY7f3IRlTdbChDBrq+PCslCkjgJfvF97HT YUsGvp63XlaEm1Xyv/RKQiUa3fkyudUZKUwkwZEMvueMR8ZaiqkWrRmRsBbwQj5V6vPP DtN5Jhtak3uclk1P4WNr6oZWbt6NmdO1+1HCuoI2OCBkfXHLxhESS6GZrTn76zsCtvHi cO6z9Nor38/187qX1wB6VqM+tklJ6iv959TzxMR6LgiRxSs/Z0OMzDV+IaTUL/COdO2h to3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690176626; x=1690781426; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TnxapSoOoqrx/JmjeK0D4Eqy+ziHuQAnxXeq35Wg/z4=; b=fIRrNGq6ciMf2Xd1gMpRDJUzqdJ+FSaKZvdoVr9uDNioTkNXW9gxtKDgM9UPS6sABP X8L7//o97aqtxm0TQQ45+hfiem3HMyEmTVJQ6ldgyVHIb3LrIQAbJC+Vd2uvY2wAiOej Zu22FWdOVviT/8MiR8IeU/wEnzW4I7NaYGrT7C1tFDD9HdjkL/HgefRcDz9QhGUxrWzZ trD/mI/tD+9XpW+0k6ou7yu8vOCTa8P2TfQNBHL++3mI1nv9ZzZolP11IeXTdTZuB6mT 0Pmm30De9EdUHi6FDqOi6s70woHOmubY/Dz4SwfCm/LRCCC5B9PUmRCE1eIhnfBQ4cE4 VZRg== X-Gm-Message-State: ABy/qLa0irUQd2I4Bxsm3ZaVgahokCztkC4iBGk73YIOCPI5xKPasg5D 4zn/DEJPSJqcOcpY37USh4MeNz6r2ig= X-Google-Smtp-Source: APBJJlHFNxoyfLX3t4i1b80DGBzxiqfEOqiDUPJWTHhotLZ5PDy1Hdbdiz1qixcmcFft00WqOMVejQ== X-Received: by 2002:a0d:d515:0:b0:573:cacd:3b6e with SMTP id x21-20020a0dd515000000b00573cacd3b6emr5678723ywd.30.1690176626563; Sun, 23 Jul 2023 22:30:26 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b8db:3c3:1ff4:2ae3]) by smtp.gmail.com with ESMTPSA id j14-20020a170902758e00b001b81a97860asm7801937pll.27.2023.07.23.22.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:30:26 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 1/5] Input: tca6416-keypad - always expect proper IRQ number in i2c client Date: Sun, 23 Jul 2023 22:30:18 -0700 Message-ID: <20230724053024.352054-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Remove option having i2c client contain raw gpio number instead of proper IRQ number. There are no users of this facility in mainline and it will allow cleaning up the driver code with regard to wakeup handling, etc. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tca6416-keypad.c | 27 +++++++++---------------- include/linux/tca6416_keypad.h | 1 - 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c index 2f745cabf4f2..01bc0b881188 100644 --- a/drivers/input/keyboard/tca6416-keypad.c +++ b/drivers/input/keyboard/tca6416-keypad.c @@ -148,7 +148,7 @@ static int tca6416_keys_open(struct input_dev *dev) if (chip->use_polling) schedule_delayed_work(&chip->dwork, msecs_to_jiffies(100)); else - enable_irq(chip->irqnum); + enable_irq(chip->client->irq); return 0; } @@ -160,7 +160,7 @@ static void tca6416_keys_close(struct input_dev *dev) if (chip->use_polling) cancel_delayed_work_sync(&chip->dwork); else - disable_irq(chip->irqnum); + disable_irq(chip->client->irq); } static int tca6416_setup_registers(struct tca6416_keypad_chip *chip) @@ -266,12 +266,7 @@ static int tca6416_keypad_probe(struct i2c_client *client) goto fail1; if (!chip->use_polling) { - if (pdata->irq_is_gpio) - chip->irqnum = gpio_to_irq(client->irq); - else - chip->irqnum = client->irq; - - error = request_threaded_irq(chip->irqnum, NULL, + error = request_threaded_irq(client->irq, NULL, tca6416_keys_isr, IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_NO_AUTOEN, @@ -279,7 +274,7 @@ static int tca6416_keypad_probe(struct i2c_client *client) if (error) { dev_dbg(&client->dev, "Unable to claim irq %d; error %d\n", - chip->irqnum, error); + client->irq, error); goto fail1; } } @@ -298,8 +293,8 @@ static int tca6416_keypad_probe(struct i2c_client *client) fail2: if (!chip->use_polling) { - free_irq(chip->irqnum, chip); - enable_irq(chip->irqnum); + free_irq(client->irq, chip); + enable_irq(client->irq); } fail1: input_free_device(input); @@ -312,8 +307,8 @@ static void tca6416_keypad_remove(struct i2c_client *client) struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); if (!chip->use_polling) { - free_irq(chip->irqnum, chip); - enable_irq(chip->irqnum); + free_irq(client->irq, chip); + enable_irq(client->irq); } input_unregister_device(chip->input); @@ -323,10 +318,9 @@ static void tca6416_keypad_remove(struct i2c_client *client) static int tca6416_keypad_suspend(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); - struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); if (device_may_wakeup(dev)) - enable_irq_wake(chip->irqnum); + enable_irq_wake(client->irq); return 0; } @@ -334,10 +328,9 @@ static int tca6416_keypad_suspend(struct device *dev) static int tca6416_keypad_resume(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); - struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); if (device_may_wakeup(dev)) - disable_irq_wake(chip->irqnum); + disable_irq_wake(client->irq); return 0; } diff --git a/include/linux/tca6416_keypad.h b/include/linux/tca6416_keypad.h index b0d36a9934cc..5cf6f6f82aa7 100644 --- a/include/linux/tca6416_keypad.h +++ b/include/linux/tca6416_keypad.h @@ -25,7 +25,6 @@ struct tca6416_keys_platform_data { unsigned int rep:1; /* enable input subsystem auto repeat */ uint16_t pinmask; uint16_t invert; - int irq_is_gpio; int use_polling; /* use polling if Interrupt is not connected*/ }; #endif From patchwork Mon Jul 24 05:30:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323448 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 06806C001DE for ; Mon, 24 Jul 2023 05:30:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229546AbjGXFad (ORCPT ); Mon, 24 Jul 2023 01:30:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbjGXFac (ORCPT ); Mon, 24 Jul 2023 01:30:32 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 366D8113; Sun, 23 Jul 2023 22:30:28 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6686708c986so3813751b3a.0; Sun, 23 Jul 2023 22:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690176627; x=1690781427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+mBfTAXdbECKfZWYSzzClNT1MWFHwf0oInN5lmMc7Zo=; b=qelQGmEM8D2UOVsGzWD/+tKcbMFqhP/rsPQhWqRpsciysH+gEYd/tQxhvO8R3RJ6uL 6TkO9G30DNNlOF0heMtpfmiRniefRngKoQbAQuL+PDWSkuL+edmHNVeTHCyRY6qB0u7Z tVTZfV1yEWCyw0bfrekOe+2I1KhK2omSKrxX5xbYx5Zqe1006+Uefmcj6IiqnQ0WaNaJ 3yJzYZMQ88tnY+xSavK2MR1pQeay5np+NXxrVz136jsaeXqUUUYppL02SBuRZCb2kYTt p2T/6fynSBpo0y8ArrOnxe8OAHR/WnFP2tFc9MHOFUO7KYE75PlEOr3nGwN9A37dsmZp iA5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690176627; x=1690781427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+mBfTAXdbECKfZWYSzzClNT1MWFHwf0oInN5lmMc7Zo=; b=eaSJt+4o4O71GTKC6MM7nuG+scvJuHTjn6QllWvpAuD8DM6JJDPgLudv2F9W7jFxY7 hqSNBvyyY2UZmC4eUqK0YXEMMvPfTp8yf1qfpHCdf9HnCc35HgWbnUJrTEVeYiwEaRiY pMr/TuDhi8uP2wwqkdW+MFiY3lJeLvVOmaCWcijp4DiZdbaQlxlGpx9/zPxt4ddcQCx9 tK9w6XjIjus4QCXu0wH/CLDa4Yq7XMPav2bCiV9skCjJz+8iQV61O6mWMJx8CQrYt6qk pvMPTiTIDiO7jTrWfhNht6uINQzbBLwAufjrqNv2aVyvihRwo6I3RkB4m6pjIaBxtmwx iMNw== X-Gm-Message-State: ABy/qLY537GyjscX6J5fjx/fwlY9unRKEFLIoLaCrfCVWDDzvg7abfvR WsMlyqYJBJ5rOiqf2A+D8f8yTNlLw/U= X-Google-Smtp-Source: APBJJlHMn/Vy0WKXwSzwW9qJEK4mwc1gnQgipnYWmICYuTlhAYX7Fxjh9UYydLw+hphrySGibltl2A== X-Received: by 2002:a17:902:ead1:b0:1bb:a4e4:54b6 with SMTP id p17-20020a170902ead100b001bba4e454b6mr2369869pld.62.1690176627406; Sun, 23 Jul 2023 22:30:27 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b8db:3c3:1ff4:2ae3]) by smtp.gmail.com with ESMTPSA id j14-20020a170902758e00b001b81a97860asm7801937pll.27.2023.07.23.22.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:30:27 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 2/5] Input: tca6416-keypad - rely on I2C core to set up suspend/resume Date: Sun, 23 Jul 2023 22:30:19 -0700 Message-ID: <20230724053024.352054-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724053024.352054-1-dmitry.torokhov@gmail.com> References: <20230724053024.352054-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org tca6416_keypad_suspend() and tca6416_keypad_resume() only configure device IRQ for wakeup. I2C core already does this by registering interrupt as a wakeup IRQ in case when device is marked as wakeup-enabled, so we can simply remove this code from the driver. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tca6416-keypad.c | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c index 01bc0b881188..906dffbf171c 100644 --- a/drivers/input/keyboard/tca6416-keypad.c +++ b/drivers/input/keyboard/tca6416-keypad.c @@ -287,7 +287,6 @@ static int tca6416_keypad_probe(struct i2c_client *client) } i2c_set_clientdata(client, chip); - device_init_wakeup(&client->dev, 1); return 0; @@ -315,33 +314,9 @@ static void tca6416_keypad_remove(struct i2c_client *client) kfree(chip); } -static int tca6416_keypad_suspend(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - - if (device_may_wakeup(dev)) - enable_irq_wake(client->irq); - - return 0; -} - -static int tca6416_keypad_resume(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - - if (device_may_wakeup(dev)) - disable_irq_wake(client->irq); - - return 0; -} - -static DEFINE_SIMPLE_DEV_PM_OPS(tca6416_keypad_dev_pm_ops, - tca6416_keypad_suspend, tca6416_keypad_resume); - static struct i2c_driver tca6416_keypad_driver = { .driver = { .name = "tca6416-keypad", - .pm = pm_sleep_ptr(&tca6416_keypad_dev_pm_ops), }, .probe = tca6416_keypad_probe, .remove = tca6416_keypad_remove, From patchwork Mon Jul 24 05:30:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323449 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 B3510C41513 for ; Mon, 24 Jul 2023 05:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbjGXFaf (ORCPT ); Mon, 24 Jul 2023 01:30:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjGXFad (ORCPT ); Mon, 24 Jul 2023 01:30:33 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF811A3; Sun, 23 Jul 2023 22:30:29 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1b9c368f4b5so31930445ad.0; Sun, 23 Jul 2023 22:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690176628; x=1690781428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V66bJv3ffs5NyeopA0TuaqhZ6vwYum3/23pBHpOv8l4=; b=V+YLo1+BHfpaEdt6D5L9vRwdhNEtxamsi7pL+3rF67yyaOj3qFTmnIY7kGJveM09qV C432RIVgidJl0AwPyrnrxzC/zNjhYpIQgYWCH9rfX95kJXxyyNoAMZMrDzGj5jQYmFgX jvYoYpHUqGLnWcFHVjHXSayY/BYz4T6IIoDgHow0ocJHRElg8J/W2mjrIkv70QtPk5db 3K2ITF/gWsX/0wsDYx32qARoMg55W9qn1zWZwmOtUim5pe0IUljETVQuPJ11tnuGQX1y Ed1mB+nkdVO695TyWGhCgkuTZTo+FajWBji1enIfXNd9STLmD4NX3liacfJNB+4x/F74 eCoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690176628; x=1690781428; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V66bJv3ffs5NyeopA0TuaqhZ6vwYum3/23pBHpOv8l4=; b=M3Gssj+t4Yfoq3xJNPXwXTXlUVtRbIHwjRBIkgYW99iIoNV0LoLQnJVjy/6JLBDZUS 95wtm0u2qFSFGT1VJPYR70jTwZMSlEuJCm4DJgznnI0XK8UiFiCrIZ0neFxh3vhIf/KT hrkgvyyHirmhzBD3CkieI2L9HeUmHw7HzjkoZakZbqM/7u6TuiE/w+LHZEm9olaM7naJ 1F5/JUkIvDyj2JMlv96n7vaE7f01JFiyBm9J3AgQgDyQmEaMA+RHGyKT/nLozovO60ii YwF8fss1KTPM++sAdixeZTKg0Zq+Qjj83B3xes9fPQAOz1FJW8D7seTYVMyparb0YFdF /Xjg== X-Gm-Message-State: ABy/qLaE8v91V4oa2zB2yHGjEqYUCX1p1d6qoPnjVUcsYmovotNKQhZs bOI8RmMyGDbJweUq68GFfKGRSR1jGDM= X-Google-Smtp-Source: APBJJlH00b55EgKKMXXsqv81oQYytRgotiqh5d6sxPwAtQNnrObdSDgo1I/HUu7GZmFrD0mPJ0kGAw== X-Received: by 2002:a17:902:ecc1:b0:1b8:c6f8:d9b with SMTP id a1-20020a170902ecc100b001b8c6f80d9bmr11689251plh.34.1690176628245; Sun, 23 Jul 2023 22:30:28 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b8db:3c3:1ff4:2ae3]) by smtp.gmail.com with ESMTPSA id j14-20020a170902758e00b001b81a97860asm7801937pll.27.2023.07.23.22.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:30:27 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] Input: tca6416-keypad - fix interrupt enable disbalance Date: Sun, 23 Jul 2023 22:30:20 -0700 Message-ID: <20230724053024.352054-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724053024.352054-1-dmitry.torokhov@gmail.com> References: <20230724053024.352054-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The driver has been switched to use IRQF_NO_AUTOEN, but in the error unwinding and remove paths calls to enable_irq() were left in place, which will lead to an incorrect enable counter value. Fixes: bcd9730a04a1 ("Input: move to use request_irq by IRQF_NO_AUTOEN flag") Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tca6416-keypad.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c index 906dffbf171c..21a2f2de4345 100644 --- a/drivers/input/keyboard/tca6416-keypad.c +++ b/drivers/input/keyboard/tca6416-keypad.c @@ -291,10 +291,8 @@ static int tca6416_keypad_probe(struct i2c_client *client) return 0; fail2: - if (!chip->use_polling) { + if (!chip->use_polling) free_irq(client->irq, chip); - enable_irq(client->irq); - } fail1: input_free_device(input); kfree(chip); @@ -305,10 +303,8 @@ static void tca6416_keypad_remove(struct i2c_client *client) { struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); - if (!chip->use_polling) { + if (!chip->use_polling) free_irq(client->irq, chip); - enable_irq(client->irq); - } input_unregister_device(chip->input); kfree(chip); From patchwork Mon Jul 24 05:30:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323447 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 78D36EB64DD for ; Mon, 24 Jul 2023 05:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229504AbjGXFad (ORCPT ); Mon, 24 Jul 2023 01:30:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjGXFac (ORCPT ); Mon, 24 Jul 2023 01:30:32 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 107B7E40; Sun, 23 Jul 2023 22:30:30 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-55c85b4b06bso1837910a12.2; Sun, 23 Jul 2023 22:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690176629; x=1690781429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rGoE1fntbnB7lNqsw0Y5id7dATDTKpa2h3lFuJESfyY=; b=CFRQYSKhzjIomrTxQg+sRqUBUBs16XaKWFyxW9nMutG+2Zojcc189NkDW+q7WOQxnD S3HWeERTKvY7N9I4rhPHEAep28x/6/89ItIsYdmwvAEXf/rplqWIxrDXfQdRzHr+RAbd Xl+pvzC/g+kge9wXQruKktoutaSrp8ueBA6sMIJhaami4AWh2bk3e6OrArdLcefUVYYU piKBB7rqk1wG3b7dfJjqDwsPkDiptC6c+q4z5wyoZrVO/QgSjYOS3e/2pwIjHrjsb0r0 qkYalMOYSGS1/ptPMmlSpr2k79B7+KGUXt9Hz+YOEjV6RDCHVM7CaAppdPDqazcDPHZf l8Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690176629; x=1690781429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rGoE1fntbnB7lNqsw0Y5id7dATDTKpa2h3lFuJESfyY=; b=Kez2m4eRmntfee8bkcADLb7ZTeNyNnoF3dqdHZNNM/y3qz37Yu+AuJ7H4uVkWgGX+Y +ORsSTyaPWrxzgtkHe002RYuQfUICJ0gtilu1xdpy1xX0U+pjp8l6QCblON0f2s+4+Sy C0QMN9GgvUWDDE6r7J8JQ1wJ8yMXt/smW2uvmhbxh2SV4P0IP5v8E7pYohFP6LQnhoSU V7JdVnP3yCUN/T1+VvE0VxUyhNIETUd3yLCbk/lV47PWlgOE8QhBpam9FU8w/7FIBM1A jZqtQEs8pmz/pkiaagDV/S3xSJGw0RpcAJqFX8SFcf9GQcaLb9aRdgr7f80OXBhaF7xI bi/g== X-Gm-Message-State: ABy/qLb5x+LZAu0Bv26BsfowbfqWfXlsd+Wp3Dn1wluEjuA0yxfid823 I4AJQQNMKWe3nC8HRmE1UYksc4eubZk= X-Google-Smtp-Source: APBJJlGppRyh3Fj1sqKunNqzpGatEQ1A/yZ8yUc/G5w2gKOOGT0Jq+IvNbNpiY8/cxvTphOajGkUHQ== X-Received: by 2002:a05:6a21:9988:b0:106:25b3:2f92 with SMTP id ve8-20020a056a21998800b0010625b32f92mr8233714pzb.52.1690176629281; Sun, 23 Jul 2023 22:30:29 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b8db:3c3:1ff4:2ae3]) by smtp.gmail.com with ESMTPSA id j14-20020a170902758e00b001b81a97860asm7801937pll.27.2023.07.23.22.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:30:28 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 4/5] Input: tca6416-keypad - convert to use devm_* api Date: Sun, 23 Jul 2023 22:30:21 -0700 Message-ID: <20230724053024.352054-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724053024.352054-1-dmitry.torokhov@gmail.com> References: <20230724053024.352054-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: Yangtao Li Use devm_* api to simplify code, this makes it unnecessary to explicitly release resources. Signed-off-by: Yangtao Li Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tca6416-keypad.c | 53 +++++++++---------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c index 21a2f2de4345..ff665319791e 100644 --- a/drivers/input/keyboard/tca6416-keypad.c +++ b/drivers/input/keyboard/tca6416-keypad.c @@ -216,12 +216,15 @@ static int tca6416_keypad_probe(struct i2c_client *client) return -EINVAL; } - chip = kzalloc(struct_size(chip, buttons, pdata->nbuttons), GFP_KERNEL); - input = input_allocate_device(); - if (!chip || !input) { - error = -ENOMEM; - goto fail1; - } + chip = devm_kzalloc(&client->dev, + struct_size(chip, buttons, pdata->nbuttons), + GFP_KERNEL); + if (!chip) + return -ENOMEM; + + input = devm_input_allocate_device(&client->dev); + if (!input) + return -ENOMEM; chip->client = client; chip->input = input; @@ -233,7 +236,6 @@ static int tca6416_keypad_probe(struct i2c_client *client) input->phys = "tca6416-keys/input0"; input->name = client->name; - input->dev.parent = &client->dev; input->open = tca6416_keys_open; input->close = tca6416_keys_close; @@ -263,19 +265,20 @@ static int tca6416_keypad_probe(struct i2c_client *client) */ error = tca6416_setup_registers(chip); if (error) - goto fail1; + return error; if (!chip->use_polling) { - error = request_threaded_irq(client->irq, NULL, - tca6416_keys_isr, - IRQF_TRIGGER_FALLING | - IRQF_ONESHOT | IRQF_NO_AUTOEN, - "tca6416-keypad", chip); + error = devm_request_threaded_irq(&client->dev, client->irq, + NULL, tca6416_keys_isr, + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT | + IRQF_NO_AUTOEN, + "tca6416-keypad", chip); if (error) { dev_dbg(&client->dev, "Unable to claim irq %d; error %d\n", client->irq, error); - goto fail1; + return error; } } @@ -283,31 +286,12 @@ static int tca6416_keypad_probe(struct i2c_client *client) if (error) { dev_dbg(&client->dev, "Unable to register input device, error: %d\n", error); - goto fail2; + return error; } i2c_set_clientdata(client, chip); return 0; - -fail2: - if (!chip->use_polling) - free_irq(client->irq, chip); -fail1: - input_free_device(input); - kfree(chip); - return error; -} - -static void tca6416_keypad_remove(struct i2c_client *client) -{ - struct tca6416_keypad_chip *chip = i2c_get_clientdata(client); - - if (!chip->use_polling) - free_irq(client->irq, chip); - - input_unregister_device(chip->input); - kfree(chip); } static struct i2c_driver tca6416_keypad_driver = { @@ -315,7 +299,6 @@ static struct i2c_driver tca6416_keypad_driver = { .name = "tca6416-keypad", }, .probe = tca6416_keypad_probe, - .remove = tca6416_keypad_remove, .id_table = tca6416_id, }; From patchwork Mon Jul 24 05:30:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323451 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 3105BEB64DD for ; Mon, 24 Jul 2023 05:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229608AbjGXFag (ORCPT ); Mon, 24 Jul 2023 01:30:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbjGXFad (ORCPT ); Mon, 24 Jul 2023 01:30:33 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0557E41; Sun, 23 Jul 2023 22:30:30 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bba48b0bd2so2504915ad.3; Sun, 23 Jul 2023 22:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690176630; x=1690781430; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=myxsHV41W/cEgCHV/ZIjTYl0IALEPxj3hWRr+N7vsnc=; b=moHLe0NX/7pk+pvyJOIFWfb6uid2+i4E7Z/Qx2iIMwzSpY3Ai1qWSI0J2RbKFLWTCr qUSv0u3jXcLy6CmTCrk65iqCscw1iduJei3nUnw/1ZPZPlV4wgRw4I//x8XiusIi2Rbb KWBrHRbGyAsdyFrBDL/zR59LcKoT+TUBwcoQp39sKkeCKp5UZrlhp8YdeZsmqtqy4Zx5 nGFBe3zxYCZTZevatAvD4dfPoa9vDSZ8HkAlThdOghusxU0MD4WSTR2VmhBFvWA66NvO CYji1DXt5fiZ7wz2eFNfzulhGYGbhdAAwicp9R4yeJYNtpsa3qxFBJS9qSs4TGHZ9duh Qp8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690176630; x=1690781430; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=myxsHV41W/cEgCHV/ZIjTYl0IALEPxj3hWRr+N7vsnc=; b=LDRMcKtPDTS4qWRA4eoo1ypozty+dEH7kHuxD/WcJKsW1g4sfBsrcrkf56PU5Vr0a2 KpD1+qhU9PH8ApDye10OyW13G9pf0EISgsWYV/hKUk2Jqu6KZEGMWKcv7988+EtNf2LR M5sycUe+PNPySNdObK5TECxz2kULoYfsrOMOwFInhFlyGQfiKnkE9q/6etxbnXD8lr63 j5NOmIadBYJEsThbjYKttvnF4+62vNnh52b2xTya9BW6sKXHf4cJlYGSImhBHs6cZ8ye btdB3nbYmBqx5TTSfq7kT93v3vilpFZmU/16cYrJ5gm1ZtVMFM0/xEzw4u65MeJFQ9M0 pEbw== X-Gm-Message-State: ABy/qLYRYNJ+IzGSeSNK4aedLuT5AXAGGTZCZnTeg7AhG7BuFyRdeIL8 pmWh29o5AkEk/YtOTD51mxbsI5PZT/s= X-Google-Smtp-Source: APBJJlEbwFWsFqhgfqgPEjkAoK4JltfHryMjWpUh0kB6xVt29YA7Dk4jCaWcG8L3JG440MTwGE/SXg== X-Received: by 2002:a17:902:d4ca:b0:1bb:5b88:73da with SMTP id o10-20020a170902d4ca00b001bb5b8873damr9344869plg.61.1690176630106; Sun, 23 Jul 2023 22:30:30 -0700 (PDT) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b8db:3c3:1ff4:2ae3]) by smtp.gmail.com with ESMTPSA id j14-20020a170902758e00b001b81a97860asm7801937pll.27.2023.07.23.22.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:30:29 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 5/5] Input: tca6416-keypad - switch to using input core's polling features Date: Sun, 23 Jul 2023 22:30:22 -0700 Message-ID: <20230724053024.352054-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724053024.352054-1-dmitry.torokhov@gmail.com> References: <20230724053024.352054-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Instead of rolling custom polling implementation use input core facilities. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/tca6416-keypad.c | 46 ++++++++++--------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/input/keyboard/tca6416-keypad.c b/drivers/input/keyboard/tca6416-keypad.c index ff665319791e..ebc8b9561266 100644 --- a/drivers/input/keyboard/tca6416-keypad.c +++ b/drivers/input/keyboard/tca6416-keypad.c @@ -24,6 +24,8 @@ #define TCA6416_INVERT 2 #define TCA6416_DIRECTION 3 +#define TCA6416_POLL_INTERVAL 100 /* msec */ + static const struct i2c_device_id tca6416_id[] = { { "tca6416-keys", 16, }, { "tca6408-keys", 8, }, @@ -43,7 +45,6 @@ struct tca6416_keypad_chip { struct i2c_client *client; struct input_dev *input; - struct delayed_work dwork; int io_size; int irqnum; u16 pinmask; @@ -85,9 +86,9 @@ static int tca6416_read_reg(struct tca6416_keypad_chip *chip, int reg, u16 *val) return 0; } -static void tca6416_keys_scan(struct tca6416_keypad_chip *chip) +static void tca6416_keys_scan(struct input_dev *input) { - struct input_dev *input = chip->input; + struct tca6416_keypad_chip *chip = input_get_drvdata(input); u16 reg_val, val; int error, i, pin_index; @@ -122,33 +123,20 @@ static void tca6416_keys_scan(struct tca6416_keypad_chip *chip) */ static irqreturn_t tca6416_keys_isr(int irq, void *dev_id) { - struct tca6416_keypad_chip *chip = dev_id; - - tca6416_keys_scan(chip); + tca6416_keys_scan(dev_id); return IRQ_HANDLED; } -static void tca6416_keys_work_func(struct work_struct *work) -{ - struct tca6416_keypad_chip *chip = - container_of(work, struct tca6416_keypad_chip, dwork.work); - - tca6416_keys_scan(chip); - schedule_delayed_work(&chip->dwork, msecs_to_jiffies(100)); -} - static int tca6416_keys_open(struct input_dev *dev) { struct tca6416_keypad_chip *chip = input_get_drvdata(dev); - /* Get initial device state in case it has switches */ - tca6416_keys_scan(chip); - - if (chip->use_polling) - schedule_delayed_work(&chip->dwork, msecs_to_jiffies(100)); - else + if (!chip->use_polling) { + /* Get initial device state in case it has switches */ + tca6416_keys_scan(dev); enable_irq(chip->client->irq); + } return 0; } @@ -157,9 +145,7 @@ static void tca6416_keys_close(struct input_dev *dev) { struct tca6416_keypad_chip *chip = input_get_drvdata(dev); - if (chip->use_polling) - cancel_delayed_work_sync(&chip->dwork); - else + if (!chip->use_polling) disable_irq(chip->client->irq); } @@ -232,8 +218,6 @@ static int tca6416_keypad_probe(struct i2c_client *client) chip->pinmask = pdata->pinmask; chip->use_polling = pdata->use_polling; - INIT_DELAYED_WORK(&chip->dwork, tca6416_keys_work_func); - input->phys = "tca6416-keys/input0"; input->name = client->name; @@ -268,12 +252,20 @@ static int tca6416_keypad_probe(struct i2c_client *client) return error; if (!chip->use_polling) { + error = input_setup_polling(input, tca6416_keys_scan); + if (error) { + dev_err(&client->dev, "Failed to setup polling\n"); + return error; + } + + input_set_poll_interval(input, TCA6416_POLL_INTERVAL); + } else { error = devm_request_threaded_irq(&client->dev, client->irq, NULL, tca6416_keys_isr, IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_NO_AUTOEN, - "tca6416-keypad", chip); + "tca6416-keypad", input); if (error) { dev_dbg(&client->dev, "Unable to claim irq %d; error %d\n",