From patchwork Mon Jul 24 05:13:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323441 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 A2183C001B0 for ; Mon, 24 Jul 2023 05:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbjGXFN5 (ORCPT ); Mon, 24 Jul 2023 01:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjGXFN4 (ORCPT ); Mon, 24 Jul 2023 01:13:56 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78D4DE40; Sun, 23 Jul 2023 22:13:50 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3a3373211a1so2373547b6e.0; Sun, 23 Jul 2023 22:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690175629; x=1690780429; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=caoeUxdk/bY/30hShXkM8xzsEfv9tOC0PQvdZObEqiY=; b=KYD9a4ljlBeWIzDK9kSM+wtkeKt3bOrazkF5Xp838g3RE1NG9jTSHD/pFsqgGvB8pH SKWeeBfl2HV2aMTyoGX3ingxOXm0C3fabo5d1/NoM8vpoxGQr/4ZPHz9e/BmSd4mRqPm u2EMUUmFr3TfhsDfhyRQTnJm2V6Lx2LsKP9XaX+yuzg463Im6sZRUnULiXsV7cdG7JYc v9Twr8zm/d9pxtQeIwPnqSO1O1c73aJZCaWwVZmb115l8Wg1lzsWQMkmvOxqnR1IxXw8 HhzI0MYiHSmvisooFrdUvjvs6Md5ffI0KQiupCqjboAphXLLFOP7F8X294iRF0eFLzsr Jt8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690175629; x=1690780429; 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=caoeUxdk/bY/30hShXkM8xzsEfv9tOC0PQvdZObEqiY=; b=OWcxKub/2T78QX4qcQty/6vxk9yvx38alH7g0uQAIdfITfhUlcdK30sN5Oxwi2Cw+I AAaRj0Hvq9b9dPQso6SP41rkK1yc2G0WjfWV67ahyIsMVNTQ/tpd9gm9yScP9pilU195 kluVqHLgxC98MVKDdj71PozXC807n9kQ7tDscdcORS2P9OpuoPvBFbrVx6w4SBdLX35U 7C6sKeWcrvTh6o7tfxUvrDxSCu7u/YsnyGWH6MoSgvHnbzN38a2TSBTWviALKrRoCk1A SAmoofEPzzpL/36ni3VehooizIqq7liYo6V3Idi8GYoHIxREW7XPPCgq44TaezxRMOc3 3SEQ== X-Gm-Message-State: ABy/qLa8akFiO0BQsXvMpj1EnNKfdxpCpAQOXirVJLK0/i5Hu7slchvQ ABb3p25etODX+vTP6Bk25lltsH/+jow= X-Google-Smtp-Source: APBJJlEDCNOx+kTZCCY18koIORa1WIU3zN1YrwleKmbxpXbt6hOx2rpIGov6fTFkU+iz2ubrKMu+dA== X-Received: by 2002:a05:6808:a97:b0:3a4:947:c97b with SMTP id q23-20020a0568080a9700b003a40947c97bmr9726446oij.0.1690175629481; Sun, 23 Jul 2023 22:13:49 -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 gv17-20020a17090b11d100b00265dc26d8dfsm7501106pjb.27.2023.07.23.22.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:13:49 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 1/4] Input: qt2160 - tweak check for i2c adapter functionality Date: Sun, 23 Jul 2023 22:13:39 -0700 Message-ID: <20230724051345.335219-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 i2c_check_functionality() returns essentially a boolean and not an error code, so treat it as such. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/qt2160.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c index 599ea85cfd30..b0b9d7a2691e 100644 --- a/drivers/input/keyboard/qt2160.c +++ b/drivers/input/keyboard/qt2160.c @@ -345,12 +345,9 @@ static int qt2160_probe(struct i2c_client *client) int i; int error; - /* Check functionality */ - error = i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_BYTE); - if (!error) { + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE)) { dev_err(&client->dev, "%s adapter not supported\n", - dev_driver_string(&client->adapter->dev)); + dev_driver_string(&client->adapter->dev)); return -ENODEV; } From patchwork Mon Jul 24 05:13:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323442 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 68668EB64DD for ; Mon, 24 Jul 2023 05:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229509AbjGXFN6 (ORCPT ); Mon, 24 Jul 2023 01:13:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbjGXFN5 (ORCPT ); Mon, 24 Jul 2023 01:13:57 -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 16874E4A; Sun, 23 Jul 2023 22:13:51 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-55ba5bb0bf3so2498470a12.1; Sun, 23 Jul 2023 22:13:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690175630; x=1690780430; 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=T97tcTSFQGPc6gGcVYrEPjC13qxr2ex/c8Suwj0RBNk=; b=aUmHYkdfM+iydYeE6Cq29eEtlaaS1Jqy+mInIVnTPDsJt2AGhMsr2uOgoB1totUJkW nb6hL+jZbZh0hkvLKsPX4i4V9UhW7cfLK+nXCbajn9hlpIGOoG6Z4jzi1TB4Hylqvqtb TTRfJDiURxaQVL8wZR6gXkoHZNqY6CvN3f+X/EklP/SO60y1ExP2EJVChdnMw1i/LtJE IZZ7BWt1JvTlUz//D/4PtHCQnU9dxpSGUlVFxv9zRizq2lCVPudhTPl2uYSdVJnzmeXi lpPh9JJxVM71d04+7rgjr0x5CF7SAn2CKdmAzdaZBtmySboL9qJaO7+7vJ4K//avvV+V EuzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690175630; x=1690780430; 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=T97tcTSFQGPc6gGcVYrEPjC13qxr2ex/c8Suwj0RBNk=; b=X4qwkQJ+ozcsRZkSyrNF3RtBADN21riaUxTsu+p8BflWqN4vk4tOIFlIDrzkpKPT/O hFPfHbEKnVY41gUAhRhTGRiSrzKtNeipeKw8fvknBbook6LfHrwNj8Aj/61EV/MxeKO1 e16DMzEJrLKlPFMfd7bh+Iv/WbxQ5OK2juFSGdas6n/1JGQOF2gk+f5c8au/NoAnZE5b tN7yeaIEi1srmWftPFMzJkSb2YUHu4iBS37mbqnbv1P4Pl8aY7VuTKB20pu0EaGmaziB nTCRNgmOOIP9sBLyZlVsYWGm+2HHCXgLGjKOQGzqm5mn2tF+z8nFz5zHz+mRkI87UIIy 7sSg== X-Gm-Message-State: ABy/qLbvgRHtKhEPiZ6hX0kh9A/rN7moT3eujOCi5DV9QxS8RnTmwIrV YKF/fw0RBUCeZT57ZHDMSswGgmygqYA= X-Google-Smtp-Source: APBJJlGb88IqWTgJxONyFVXsBNHaRHTl1+rfN3MMSp9txoVwvgyUSrkydDlNAAnMs2QwjlSeujXnQw== X-Received: by 2002:a17:90b:4d83:b0:263:eb0e:5681 with SMTP id oj3-20020a17090b4d8300b00263eb0e5681mr12020167pjb.3.1690175630233; Sun, 23 Jul 2023 22:13:50 -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 gv17-20020a17090b11d100b00265dc26d8dfsm7501106pjb.27.2023.07.23.22.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:13:49 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] Input: qt2160 - switch to using threaded interrupt handler Date: Sun, 23 Jul 2023 22:13:40 -0700 Message-ID: <20230724051345.335219-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724051345.335219-1-dmitry.torokhov@gmail.com> References: <20230724051345.335219-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Instead of using combination of normal IRQ and work item which required careful handling on device teardown, use standard threaded interrupt that allows communication wityh the chip over slow (I2C) bus directly in the interrupt handler. To support polling mode switch to standard polling support implemented by the input core. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/qt2160.c | 53 ++++++++++++--------------------- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c index b0b9d7a2691e..b8c0f0ebf604 100644 --- a/drivers/input/keyboard/qt2160.c +++ b/drivers/input/keyboard/qt2160.c @@ -32,7 +32,7 @@ #define QT2160_NUM_LEDS_X 8 -#define QT2160_CYCLE_INTERVAL (2*HZ) +#define QT2160_CYCLE_INTERVAL 2000 /* msec - 2 sec */ static unsigned char qt2160_key2code[] = { KEY_0, KEY_1, KEY_2, KEY_3, @@ -54,7 +54,6 @@ struct qt2160_led { struct qt2160_data { struct i2c_client *client; struct input_dev *input; - struct delayed_work dwork; unsigned short keycodes[ARRAY_SIZE(qt2160_key2code)]; u16 key_matrix; #ifdef CONFIG_LEDS_CLASS @@ -155,10 +154,10 @@ static int qt2160_read_block(struct i2c_client *client, return 0; } -static int qt2160_get_key_matrix(struct qt2160_data *qt2160) +static void qt2160_get_key_matrix(struct input_dev *input) { + struct qt2160_data *qt2160 = input_get_drvdata(input); struct i2c_client *client = qt2160->client; - struct input_dev *input = qt2160->input; u8 regs[6]; u16 old_matrix, new_matrix; int ret, i, mask; @@ -173,7 +172,7 @@ static int qt2160_get_key_matrix(struct qt2160_data *qt2160) if (ret) { dev_err(&client->dev, "could not perform chip read.\n"); - return ret; + return; } old_matrix = qt2160->key_matrix; @@ -191,37 +190,17 @@ static int qt2160_get_key_matrix(struct qt2160_data *qt2160) } input_sync(input); - - return 0; } -static irqreturn_t qt2160_irq(int irq, void *_qt2160) +static irqreturn_t qt2160_irq(int irq, void *data) { - struct qt2160_data *qt2160 = _qt2160; + struct input_dev *input = data; - mod_delayed_work(system_wq, &qt2160->dwork, 0); + qt2160_get_key_matrix(input); return IRQ_HANDLED; } -static void qt2160_schedule_read(struct qt2160_data *qt2160) -{ - schedule_delayed_work(&qt2160->dwork, QT2160_CYCLE_INTERVAL); -} - -static void qt2160_worker(struct work_struct *work) -{ - struct qt2160_data *qt2160 = - container_of(work, struct qt2160_data, dwork.work); - - dev_dbg(&qt2160->client->dev, "worker\n"); - - qt2160_get_key_matrix(qt2160); - - /* Avoid device lock up by checking every so often */ - qt2160_schedule_read(qt2160); -} - static int qt2160_read(struct i2c_client *client, u8 reg) { int ret; @@ -365,7 +344,6 @@ static int qt2160_probe(struct i2c_client *client) qt2160->client = client; qt2160->input = input; - INIT_DELAYED_WORK(&qt2160->dwork, qt2160_worker); input->name = "AT42QT2160 Touch Sense Keyboard"; input->id.bustype = BUS_I2C; @@ -382,6 +360,8 @@ static int qt2160_probe(struct i2c_client *client) } __clear_bit(KEY_RESERVED, input->keybit); + input_set_drvdata(input, qt2160); + /* Calibrate device */ error = qt2160_write(client, QT2160_CMD_CALIBRATE, 1); if (error) { @@ -390,13 +370,21 @@ static int qt2160_probe(struct i2c_client *client) } if (client->irq) { - error = request_irq(client->irq, qt2160_irq, - IRQF_TRIGGER_FALLING, "qt2160", qt2160); + error = request_threaded_irq(client->irq, NULL, qt2160_irq, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "qt2160", input); if (error) { dev_err(&client->dev, "failed to allocate irq %d\n", client->irq); goto err_free_mem; } + } else { + error = input_setup_polling(input, qt2160_get_key_matrix); + if (error) { + dev_err(&client->dev, "Failed to setup polling\n"); + goto err_free_mem; + } + input_set_poll_interval(input, QT2160_CYCLE_INTERVAL); } error = qt2160_register_leds(qt2160); @@ -413,7 +401,6 @@ static int qt2160_probe(struct i2c_client *client) } i2c_set_clientdata(client, qt2160); - qt2160_schedule_read(qt2160); return 0; @@ -438,8 +425,6 @@ static void qt2160_remove(struct i2c_client *client) if (client->irq) free_irq(client->irq, qt2160); - cancel_delayed_work_sync(&qt2160->dwork); - input_unregister_device(qt2160->input); kfree(qt2160); } From patchwork Mon Jul 24 05:13:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323443 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 0AD2AC001DE for ; Mon, 24 Jul 2023 05:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229811AbjGXFN7 (ORCPT ); Mon, 24 Jul 2023 01:13:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjGXFN6 (ORCPT ); Mon, 24 Jul 2023 01:13:58 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 193BDE54; Sun, 23 Jul 2023 22:13:52 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-2632336f75fso2496906a91.3; Sun, 23 Jul 2023 22:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690175631; x=1690780431; 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=TqW8DfZ6fP+85CmTsJVzjeFdh5CJjlffb6mkzwyRRAA=; b=Tlc1MlavR+Wldxpwq4X5o+8CWM7f7kxeQC4dmahGNQQetc8PON7FoURC6vPsEYZvJB 7+OOHFLM6NASIqpsBr8SBXN/6zacIwRGDzy2k5A4/D6oJYBUPgheH39SaP0fFEeY2xrG gDQWXHzjhlC0pK7dQOUh1ghuZzHL1k5JkBKx9J+5vrRjZNrA9rnIz8qXBazD6NyerZLK UpcK9GXTEqLCXQHQ9SQCUqbNfopRqoKYcuU5lDIOmW/mldOqYuLb4zr7v6wfXO6tJAbC AvAJRdYPPz0ehJFhxnskvKKIdLyAR718xeKz/TSCz78vN67ZFV421Hh/ZjK6as5gXdSc cV5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690175631; x=1690780431; 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=TqW8DfZ6fP+85CmTsJVzjeFdh5CJjlffb6mkzwyRRAA=; b=AGRVCNcW9hNeOVXCqq6PPe2azXZ8BbFxB4d8mwy2u6xseFEnZzK3wbdSCzBtbv4QEA BgX1ObXEC8ie5w4PnRPDEJOtZfk4F1xFf/SV35Lx6bM65ke44FEDmC8rZ8YyvZGaumDj TzxLtsIElJAv1QVnPaUJAndANONvx7L3Asn+hFiEOrq0i37qR4Hw88+VHza/hC89PxBc DlCDt5YXx+yPk/LbxL8eo7WbRB/kBZDLdCZBTs14W9GtXdOl31iW2KNnf2DkGNgwTJw6 GyCfL5fE8ylURIRtfSPu/A+sfqI8SITFCfjkOC1l0kyF3Aex3XtUO8qk2HJt3QZ1gIPk hGaw== X-Gm-Message-State: ABy/qLbGBg4OwUpRL0kTy1oWGYTi98k1HNXeCkiBwKztsDVtIE0+B9Su btceiAZBF+n9sPLxcCDipIFGc7Dw7FA= X-Google-Smtp-Source: APBJJlH0Im8QdnVDV93025+Hbwmqv/NIDLqn4PdqoTzvlK5Q+axm2BFQ63P3SnqiCMS6ZM9l0jtNPw== X-Received: by 2002:a17:90b:3711:b0:268:13c4:b800 with SMTP id mg17-20020a17090b371100b0026813c4b800mr2499791pjb.21.1690175631102; Sun, 23 Jul 2023 22:13:51 -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 gv17-20020a17090b11d100b00265dc26d8dfsm7501106pjb.27.2023.07.23.22.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:13:50 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] Input: qt2160 - do not hard code interrupt trigger Date: Sun, 23 Jul 2023 22:13:41 -0700 Message-ID: <20230724051345.335219-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724051345.335219-1-dmitry.torokhov@gmail.com> References: <20230724051345.335219-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Rely on the platform and ACPI/DT to set up the interrupt trigger. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/qt2160.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c index b8c0f0ebf604..6cfaabd10482 100644 --- a/drivers/input/keyboard/qt2160.c +++ b/drivers/input/keyboard/qt2160.c @@ -371,8 +371,7 @@ static int qt2160_probe(struct i2c_client *client) if (client->irq) { error = request_threaded_irq(client->irq, NULL, qt2160_irq, - IRQF_TRIGGER_LOW | IRQF_ONESHOT, - "qt2160", input); + IRQF_ONESHOT, "qt2160", input); if (error) { dev_err(&client->dev, "failed to allocate irq %d\n", client->irq); From patchwork Mon Jul 24 05:13:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13323444 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 120F5C00528 for ; Mon, 24 Jul 2023 05:14:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbjGXFOA (ORCPT ); Mon, 24 Jul 2023 01:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjGXFN7 (ORCPT ); Mon, 24 Jul 2023 01:13:59 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCB13E47; Sun, 23 Jul 2023 22:13:52 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-55ae51a45deso1863465a12.3; Sun, 23 Jul 2023 22:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690175632; x=1690780432; 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=03EJWrFuVnN7Ttag8T1UjPvKeFWGUuTA0IYhmoMhgg0=; b=FiusPs/hFTgSo1KubGOMb8AhhcHl9uCi6O38VK/7Hy02JOrKsymMaqBf/LtSrmhy79 Sie/LjQYh76DqR5hMBW53/9jh58c1Fts+6s9hgCwJ4O4WoAZTLhhUnCq8lVF4Zl8K9AD BNE8yrHpqhIOzQTUBanNCVTMi7TZ/RIBGxvSitsaQdkkpojKaQJ8ONLfVgJBrYb5juSx sPd0ZfEFG/FqDhA9cTIkoj5+qJTVXelxjhixuDacyuoOSaga+LmIXkfl7IIexfE8I0l9 ZuyGKL9vlH+gFX+7YalSMX4Tas40z9XlnLm/AQ5LxcjebTi3GiishznjFcL2dwJ6wYET XMRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690175632; x=1690780432; 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=03EJWrFuVnN7Ttag8T1UjPvKeFWGUuTA0IYhmoMhgg0=; b=BjEXachNGXAoskfRP/PMg9XM7T9sAt9kMZuxrTEib3bV91x9uGH16opnXkHb2nyc1l 4iwGGD/A9iwrq4mzgaVc9NSysvdFo9umfT0opQEO3tzbulIjFgJySbsjmOJ+4DNQ2aHi 74eL3MVhc30+fkODbyKEnimLZ4FQKFvwrF+lQKJKTQLlKcxVrDYVjFMCXTIF67JKPdZb 2INBaU/U7+tyPEeT/gocA0Bk9QS6JWh8F0rmfBfrcJcrd4KWDLFYpx3MZ7m00y5YCBKs 6tt22flfwLq1HhjyU+pgH3jN1QvLGPAxgTWLiBF4wjvViK4G6BZm7DoKCTb8VfzmU1zs qP8g== X-Gm-Message-State: ABy/qLY1LlzKYxCzCDnT20JXr2wWmsep9sWkVTwN2McvE0PE8hsYLyuk MmDnUbcDcvaVhZmmDExfBxhcqafDQpg= X-Google-Smtp-Source: APBJJlH2b2TLnA+/XQ9lY/4HOD8AV018YZJ4STZy72ICtUXvyaLXUK0m1SINjFMDdyXk6kXvXk9QzQ== X-Received: by 2002:a17:90a:66c6:b0:262:ce8f:a3e with SMTP id z6-20020a17090a66c600b00262ce8f0a3emr5539310pjl.42.1690175631957; Sun, 23 Jul 2023 22:13:51 -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 gv17-20020a17090b11d100b00265dc26d8dfsm7501106pjb.27.2023.07.23.22.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Jul 2023 22:13:51 -0700 (PDT) From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Yangtao Li , linux-kernel@vger.kernel.org Subject: [PATCH 4/4] Input: qt2160 - convert to use devm_* api Date: Sun, 23 Jul 2023 22:13:42 -0700 Message-ID: <20230724051345.335219-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724051345.335219-1-dmitry.torokhov@gmail.com> References: <20230724051345.335219-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 Link: https://lore.kernel.org/r/20230714080611.81302-7-frank.li@vivo.com Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/qt2160.c | 77 +++++++++------------------------ 1 file changed, 20 insertions(+), 57 deletions(-) diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c index 6cfaabd10482..7e3b09642ab7 100644 --- a/drivers/input/keyboard/qt2160.c +++ b/drivers/input/keyboard/qt2160.c @@ -239,7 +239,7 @@ static int qt2160_write(struct i2c_client *client, u8 reg, u8 data) static int qt2160_register_leds(struct qt2160_data *qt2160) { struct i2c_client *client = qt2160->client; - int ret; + int error; int i; for (i = 0; i < QT2160_NUM_LEDS_X; i++) { @@ -252,9 +252,9 @@ static int qt2160_register_leds(struct qt2160_data *qt2160) led->id = i; led->qt2160 = qt2160; - ret = led_classdev_register(&client->dev, &led->cdev); - if (ret < 0) - return ret; + error = devm_led_classdev_register(&client->dev, &led->cdev); + if (error) + return error; } /* Tur off LEDs */ @@ -265,14 +265,6 @@ static int qt2160_register_leds(struct qt2160_data *qt2160) return 0; } -static void qt2160_unregister_leds(struct qt2160_data *qt2160) -{ - int i; - - for (i = 0; i < QT2160_NUM_LEDS_X; i++) - led_classdev_unregister(&qt2160->leds[i].cdev); -} - #else static inline int qt2160_register_leds(struct qt2160_data *qt2160) @@ -280,10 +272,6 @@ static inline int qt2160_register_leds(struct qt2160_data *qt2160) return 0; } -static inline void qt2160_unregister_leds(struct qt2160_data *qt2160) -{ -} - #endif static bool qt2160_identify(struct i2c_client *client) @@ -334,13 +322,13 @@ static int qt2160_probe(struct i2c_client *client) return -ENODEV; /* Chip is valid and active. Allocate structure */ - qt2160 = kzalloc(sizeof(struct qt2160_data), GFP_KERNEL); - input = input_allocate_device(); - if (!qt2160 || !input) { - dev_err(&client->dev, "insufficient memory\n"); - error = -ENOMEM; - goto err_free_mem; - } + qt2160 = devm_kzalloc(&client->dev, sizeof(*qt2160), GFP_KERNEL); + if (!qt2160) + return -ENOMEM; + + input = devm_input_allocate_device(&client->dev); + if (!input) + return -ENOMEM; qt2160->client = client; qt2160->input = input; @@ -366,22 +354,24 @@ static int qt2160_probe(struct i2c_client *client) error = qt2160_write(client, QT2160_CMD_CALIBRATE, 1); if (error) { dev_err(&client->dev, "failed to calibrate device\n"); - goto err_free_mem; + return error; } if (client->irq) { - error = request_threaded_irq(client->irq, NULL, qt2160_irq, - IRQF_ONESHOT, "qt2160", input); + error = devm_request_threaded_irq(&client->dev, client->irq, + NULL, qt2160_irq, + IRQF_ONESHOT, + "qt2160", input); if (error) { dev_err(&client->dev, "failed to allocate irq %d\n", client->irq); - goto err_free_mem; + return error; } } else { error = input_setup_polling(input, qt2160_get_key_matrix); if (error) { dev_err(&client->dev, "Failed to setup polling\n"); - goto err_free_mem; + return error; } input_set_poll_interval(input, QT2160_CYCLE_INTERVAL); } @@ -389,43 +379,17 @@ static int qt2160_probe(struct i2c_client *client) error = qt2160_register_leds(qt2160); if (error) { dev_err(&client->dev, "Failed to register leds\n"); - goto err_free_irq; + return error; } error = input_register_device(qt2160->input); if (error) { dev_err(&client->dev, "Failed to register input device\n"); - goto err_unregister_leds; + return error; } - i2c_set_clientdata(client, qt2160); - return 0; - -err_unregister_leds: - qt2160_unregister_leds(qt2160); -err_free_irq: - if (client->irq) - free_irq(client->irq, qt2160); -err_free_mem: - input_free_device(input); - kfree(qt2160); - return error; -} - -static void qt2160_remove(struct i2c_client *client) -{ - struct qt2160_data *qt2160 = i2c_get_clientdata(client); - - qt2160_unregister_leds(qt2160); - - /* Release IRQ so no queue will be scheduled */ - if (client->irq) - free_irq(client->irq, qt2160); - - input_unregister_device(qt2160->input); - kfree(qt2160); } static const struct i2c_device_id qt2160_idtable[] = { @@ -442,7 +406,6 @@ static struct i2c_driver qt2160_driver = { .id_table = qt2160_idtable, .probe = qt2160_probe, - .remove = qt2160_remove, }; module_i2c_driver(qt2160_driver);