From patchwork Sun Jan 21 05:32:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 764930 Received: from mail-yw1-f169.google.com (mail-yw1-f169.google.com [209.85.128.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9534A2EB0C; Sun, 21 Jan 2024 05:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705815159; cv=none; b=fE4hmn0e/9eD2he64i0OOp9h27oHXrMlOX5sPHqG52Mz4ko8vnpwaAWZrrnw9Da4QhieimoLCxs91v5w0kVscGXtddyPFAa7A0HuFGDA4DPWlTaGtQsMQL5MEezJNuxMb3KSoXPhmuSl547mtg31V0rZCBPnwhnskYAQWF7QrIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705815159; c=relaxed/simple; bh=kDs/gHMG46M1CA5pRp7+yWHyLg9b6bCwP0OjJBW+ZRU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rXjfHnaSWKyghYq5wGJkwPOB3wubyYF1q1/fzPz+bngXt/k6AM311REufbcsvI6ZfPBx3dPagc+EmN/694KkiG5/7sJJ3C42mBePf5a7IrbFEtbFxiQGrTrmFEK2oojOTeQ334TvOv/QD42CIlymkAhdMUbrByPwUXvd2cz3TiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VX9WYU23; arc=none smtp.client-ip=209.85.128.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VX9WYU23" Received: by mail-yw1-f169.google.com with SMTP id 00721157ae682-5ffb07bdce2so7406597b3.2; Sat, 20 Jan 2024 21:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705815156; x=1706419956; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OHkj/zEKHXm2Shyb5HJF8APWEjoB9yOi3ptmZt3zAB4=; b=VX9WYU23+TKy7SALPG2+b+/C6TT4srvq3z5SbzJ96j0Y1YNfLR5YxkhBuBh3ufmeDB lYed/phW7uzhwxvIO9grQOGFkb7tmngZGiIiDxun5eqTiNBu/ACAI4+qabYzHiodcHs7 sU8EEPHehxCja6oumFqf7AGJD56HF3i9gJiC2B+H6OTSlsXwf/aNB6px/x8OgkLBe4ZZ jS6mm/f8bCEpjjcHittGCtLmdF1Dh/bCcwlmJ8Nh4iFQgZK2rwBs1l5vIxR5bdcOwHCX 71J6ohMBkJ32GLa9whXS997TQ+ukBslH6uI52XgwO3pa8Q52fPgybrctdMSnsBgkmbUh nPvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705815156; x=1706419956; 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=OHkj/zEKHXm2Shyb5HJF8APWEjoB9yOi3ptmZt3zAB4=; b=Z87HqiiUWVxgwnoKV3QAFdNEIJfv8xDdM/jsGXC6mFNrfb6+fUw0ZeOIORaE7w+Sfd 7ri3dKuSShO+j71qrO6LCNvIrSB60aNe9Ezx4n4623E9Smvh3rjWdATTzNVC3CpR3tck Km7j2snS2QnKQHl2CZ5kAMKpzUamFkRwiwV8oLvS4TMjWuqsjQly+Sk1oacKG/UUcatr ALkte0d49Qf6lcR5SdAzIxQI92CMHf2J4kup1qB8CBENTChZgrU/LXkrS0g1mu0+sFh1 FOtA8//qYCbYDTTbgOBYdXtam23fpSxMs0MBr2f04w/9l0Ws6JJuTyjcghPdLVb8ubg4 lT1w== X-Gm-Message-State: AOJu0Yy75h3JHIa89DTMsRCC+iQAOWTmj7MGxfO+KU1MR/CHfh6GDEux ebFvONG20/r4ehmTh1Nqr+IYwGr4Xl5afyTqlXb6KP7H9OMT9YdtTcDjgagi X-Google-Smtp-Source: AGHT+IFkpUlmfnQ2TzdRcfycNerdMBgBU/2Bf0f+1KtRCpBlOTwZvxsLfbfpWs7sDDx3TNsnDlcMPA== X-Received: by 2002:a81:7746:0:b0:5ff:95a8:945 with SMTP id s67-20020a817746000000b005ff95a80945mr2253046ywc.88.1705815156224; Sat, 20 Jan 2024 21:32:36 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b227:ab83:6b35:c967]) by smtp.gmail.com with ESMTPSA id mg7-20020a170903348700b001d69badff91sm5323978plb.148.2024.01.20.21.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 21:32:35 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Dan Carpenter , Bartosz Golaszewski Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/3] Input: matrix_keypad - avoid repeatedly converting GPIO to IRQ Date: Sat, 20 Jan 2024 21:32:28 -0800 Message-ID: <20240121053232.276968-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 gpio_to_irq() is getting more expensive and may require sleeping. Convert row GPIOs to interrupt numbers once in probe() and use this information when the driver needs to enable or disable given interrupt line. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 48 ++++++++++++++------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 50fa764c82d2..1cd1ffb80401 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -27,6 +27,7 @@ struct matrix_keypad { const struct matrix_keypad_platform_data *pdata; struct input_dev *input_dev; unsigned int row_shift; + unsigned int row_irqs[MATRIX_MAX_ROWS]; DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS); @@ -92,7 +93,7 @@ static void enable_row_irqs(struct matrix_keypad *keypad) enable_irq(pdata->clustered_irq); else { for (i = 0; i < pdata->num_row_gpios; i++) - enable_irq(gpio_to_irq(pdata->row_gpios[i])); + enable_irq(keypad->row_irqs[i]); } } @@ -105,7 +106,7 @@ static void disable_row_irqs(struct matrix_keypad *keypad) disable_irq_nosync(pdata->clustered_irq); else { for (i = 0; i < pdata->num_row_gpios; i++) - disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i])); + disable_irq_nosync(keypad->row_irqs[i]); } } @@ -233,7 +234,6 @@ static void matrix_keypad_stop(struct input_dev *dev) static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad) { const struct matrix_keypad_platform_data *pdata = keypad->pdata; - unsigned int gpio; int i; if (pdata->clustered_irq > 0) { @@ -241,21 +241,16 @@ static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad) keypad->gpio_all_disabled = true; } else { - for (i = 0; i < pdata->num_row_gpios; i++) { - if (!test_bit(i, keypad->disabled_gpios)) { - gpio = pdata->row_gpios[i]; - - if (enable_irq_wake(gpio_to_irq(gpio)) == 0) + for (i = 0; i < pdata->num_row_gpios; i++) + if (!test_bit(i, keypad->disabled_gpios)) + if (enable_irq_wake(keypad->row_irqs[i]) == 0) __set_bit(i, keypad->disabled_gpios); - } - } } } static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad) { const struct matrix_keypad_platform_data *pdata = keypad->pdata; - unsigned int gpio; int i; if (pdata->clustered_irq > 0) { @@ -264,12 +259,9 @@ static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad) keypad->gpio_all_disabled = false; } } else { - for (i = 0; i < pdata->num_row_gpios; i++) { - if (test_and_clear_bit(i, keypad->disabled_gpios)) { - gpio = pdata->row_gpios[i]; - disable_irq_wake(gpio_to_irq(gpio)); - } - } + for (i = 0; i < pdata->num_row_gpios; i++) + if (test_and_clear_bit(i, keypad->disabled_gpios)) + disable_irq_wake(keypad->row_irqs[i]); } } @@ -306,7 +298,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, struct matrix_keypad *keypad) { const struct matrix_keypad_platform_data *pdata = keypad->pdata; - int i, err; + int i, irq, err; /* initialized strobe lines as outputs, activated */ for (i = 0; i < pdata->num_col_gpios; i++) { @@ -345,11 +337,19 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, } } else { for (i = 0; i < pdata->num_row_gpios; i++) { - err = request_any_context_irq( - gpio_to_irq(pdata->row_gpios[i]), + irq = gpio_to_irq(pdata->row_gpios[i]); + if (irq < 0) { + err = irq; + dev_err(&pdev->dev, + "Unable to convert GPIO line %i to irq: %d\n", + pdata->row_gpios[i], err); + goto err_free_irqs; + } + + err = request_any_context_irq(irq, matrix_keypad_interrupt, IRQF_TRIGGER_RISING | - IRQF_TRIGGER_FALLING, + IRQF_TRIGGER_FALLING, "matrix-keypad", keypad); if (err < 0) { dev_err(&pdev->dev, @@ -357,6 +357,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, pdata->row_gpios[i]); goto err_free_irqs; } + + keypad->row_irqs[i] = irq; } } @@ -366,7 +368,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, err_free_irqs: while (--i >= 0) - free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad); + free_irq(keypad->row_irqs[i], keypad); i = pdata->num_row_gpios; err_free_rows: while (--i >= 0) @@ -388,7 +390,7 @@ static void matrix_keypad_free_gpio(struct matrix_keypad *keypad) free_irq(pdata->clustered_irq, keypad); } else { for (i = 0; i < pdata->num_row_gpios; i++) - free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad); + free_irq(keypad->row_irqs[i], keypad); } for (i = 0; i < pdata->num_row_gpios; i++) From patchwork Sun Jan 21 05:32:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 764537 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 865ED2EB19; Sun, 21 Jan 2024 05:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705815160; cv=none; b=ehajHifneJpG0GO4px9bpcRkCsQNoXtl5XcT0/pegLb2fRT9rpp+RpwU7323CPN5HbXyZaIS6lIAKzd2JzsErvvdLlZ6zNHmqvP9Tw0POGa/j0ItoLES3J/qiK4Q8aPTxaFdIbeL3Keyrx73xAux7sVOxdTSAUYy92MemLWnpgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705815160; c=relaxed/simple; bh=LHz06Lyhxlmi9enxiiPXvlRXe6QQ2nBa6+/km1b7dcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZQhLZehuCSo1rUlupa/gRa8nD1ZSLMRwOLNrpbrlQKpcJGo5T3hvXOOa3EPUEUnsGSshuvgW7h+dn604mcOsrITVL7Lb33MV307h3K8uwNpZMLNexjq8/GYSHhAmIfqBmlzQzbvo2U+GfQyeM9pc/XqMFBq+SrGc+4RFbUvozDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cyjKsxio; arc=none smtp.client-ip=209.85.160.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cyjKsxio" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-204f50f305cso1404138fac.3; Sat, 20 Jan 2024 21:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705815157; x=1706419957; darn=vger.kernel.org; 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=dBrp1Ps9xzLA8SOiLy9P8sSqne7yU34XilTqawEafXQ=; b=cyjKsxioQuWiuuMRSf/B+Il04uPIHZKQrOIF1has5+1IpaUJAt5ZHRUHHLj67IwssQ GI1XoEhiLdw/EhGskliZ1FVKMCokZtcnq/K2FCc/zbnX3zwv/MvaAsG22L6OkzpjIjRh tZFQ2Rs/Z6j9otysz9VwmowdlMlV8NVdrxpVDazA0S9u7iVA7LkmuO5kBZngfCSnE0oE SPUeVChh1Cx6KIvpnYYz0BJrpnc3f23srT25bR3bdSeBXNTf8KDdR3qp1YH3qaj8YRsH Qvs+c7A8z0XvelVCQPgQvVJ50EbU6XTfOGNIe2umKOuDtmYMTttM43n/EfMuiV1slzrL zqcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705815157; x=1706419957; 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=dBrp1Ps9xzLA8SOiLy9P8sSqne7yU34XilTqawEafXQ=; b=LwUvnGbHgaYvzmr1r4x8YbLDODaMCHzdoxZW3kYe9GuitaWpMR8kIBf7G5/81/IZM0 08nHG7lKyibvijmfAgohoZFhuMwbOFPI3G6O1jYfspAMcx6hkQ8NwMYQIHGNPvKKk+ZK kFuWG+3WhOp2bBqo0dtiEfHA/ihD8MpsFxexdNOsQJoxIQVZG3airbFqT2uk0WkAQi/u R/Xc5FjaIznE5BYud4U2sQGbg8AUwI0E+sPddXSIixMT2g08db/uG8H/JOr2rLBJx/o8 RhbyQ7RcNN47PnbSONV3SSvB82w2rln6GP0GVTSZGfIJPsy56eLk2UvxNdfIOSRnP/9u T/8Q== X-Gm-Message-State: AOJu0YxLcWj4UsIy8YHkcMZOio/MFW7M3mO5/eXVMRUx7W8cUqg1kwb+ aRPEWU55HMqKsneFLeXo73cNjaoOsV/ZhMYHrc6FpfTZOswxYLYM3LaJUwzv X-Google-Smtp-Source: AGHT+IE0RMaZJ7Yi27VLKIXrVx8VSF8t+AZp+vVrzIIL354OByUQiTDitByd0TmI3u0pTWeDRY/6tA== X-Received: by 2002:a05:6870:63a9:b0:214:2677:8b08 with SMTP id t41-20020a05687063a900b0021426778b08mr2200285oap.90.1705815157140; Sat, 20 Jan 2024 21:32:37 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b227:ab83:6b35:c967]) by smtp.gmail.com with ESMTPSA id mg7-20020a170903348700b001d69badff91sm5323978plb.148.2024.01.20.21.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 21:32:36 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Dan Carpenter , Bartosz Golaszewski Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/3] Input: matrix_keypad - consolidate handling of clustered interrupt Date: Sat, 20 Jan 2024 21:32:29 -0800 Message-ID: <20240121053232.276968-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240121053232.276968-1-dmitry.torokhov@gmail.com> References: <20240121053232.276968-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that the driver stores interrupt numbers corresponding to individual GPIOs in non-clustered mode, it is possible to unify handling of both modes by storing clustered interrupt at position 0 and setting the number of interrupts in this case to 1. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 63 ++++++++------------------ 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 1cd1ffb80401..44ef600b8f19 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -27,9 +27,10 @@ struct matrix_keypad { const struct matrix_keypad_platform_data *pdata; struct input_dev *input_dev; unsigned int row_shift; - unsigned int row_irqs[MATRIX_MAX_ROWS]; - DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS); + unsigned int row_irqs[MATRIX_MAX_ROWS]; + unsigned int num_row_irqs; + DECLARE_BITMAP(wakeup_enabled_irqs, MATRIX_MAX_ROWS); uint32_t last_key_state[MATRIX_MAX_COLS]; struct delayed_work work; @@ -86,28 +87,18 @@ static bool row_asserted(const struct matrix_keypad_platform_data *pdata, static void enable_row_irqs(struct matrix_keypad *keypad) { - const struct matrix_keypad_platform_data *pdata = keypad->pdata; int i; - if (pdata->clustered_irq > 0) - enable_irq(pdata->clustered_irq); - else { - for (i = 0; i < pdata->num_row_gpios; i++) - enable_irq(keypad->row_irqs[i]); - } + for (i = 0; i < keypad->num_row_irqs; i++) + enable_irq(keypad->row_irqs[i]); } static void disable_row_irqs(struct matrix_keypad *keypad) { - const struct matrix_keypad_platform_data *pdata = keypad->pdata; int i; - if (pdata->clustered_irq > 0) - disable_irq_nosync(pdata->clustered_irq); - else { - for (i = 0; i < pdata->num_row_gpios; i++) - disable_irq_nosync(keypad->row_irqs[i]); - } + for (i = 0; i < keypad->num_row_irqs; i++) + disable_irq_nosync(keypad->row_irqs[i]); } /* @@ -233,35 +224,20 @@ static void matrix_keypad_stop(struct input_dev *dev) static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad) { - const struct matrix_keypad_platform_data *pdata = keypad->pdata; int i; - if (pdata->clustered_irq > 0) { - if (enable_irq_wake(pdata->clustered_irq) == 0) - keypad->gpio_all_disabled = true; - } else { - - for (i = 0; i < pdata->num_row_gpios; i++) - if (!test_bit(i, keypad->disabled_gpios)) - if (enable_irq_wake(keypad->row_irqs[i]) == 0) - __set_bit(i, keypad->disabled_gpios); - } + for_each_clear_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) + if (enable_irq_wake(keypad->row_irqs[i]) == 0) + __set_bit(i, keypad->wakeup_enabled_irqs); } static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad) { - const struct matrix_keypad_platform_data *pdata = keypad->pdata; int i; - if (pdata->clustered_irq > 0) { - if (keypad->gpio_all_disabled) { - disable_irq_wake(pdata->clustered_irq); - keypad->gpio_all_disabled = false; - } - } else { - for (i = 0; i < pdata->num_row_gpios; i++) - if (test_and_clear_bit(i, keypad->disabled_gpios)) - disable_irq_wake(keypad->row_irqs[i]); + for_each_set_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) { + disable_irq_wake(keypad->row_irqs[i]); + __clear_bit(i, keypad->wakeup_enabled_irqs); } } @@ -335,6 +311,9 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, "Unable to acquire clustered interrupt\n"); goto err_free_rows; } + + keypad->row_irqs[0] = pdata->clustered_irq; + keypad->num_row_irqs = 1; } else { for (i = 0; i < pdata->num_row_gpios; i++) { irq = gpio_to_irq(pdata->row_gpios[i]); @@ -360,6 +339,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, keypad->row_irqs[i] = irq; } + + keypad->num_row_irqs = pdata->num_row_gpios; } /* initialized as disabled - enabled by input->open */ @@ -386,12 +367,8 @@ static void matrix_keypad_free_gpio(struct matrix_keypad *keypad) const struct matrix_keypad_platform_data *pdata = keypad->pdata; int i; - if (pdata->clustered_irq > 0) { - free_irq(pdata->clustered_irq, keypad); - } else { - for (i = 0; i < pdata->num_row_gpios; i++) - free_irq(keypad->row_irqs[i], keypad); - } + for (i = 0; i < keypad->num_row_irqs; i++) + free_irq(keypad->row_irqs[i], keypad); for (i = 0; i < pdata->num_row_gpios; i++) gpio_free(pdata->row_gpios[i]); From patchwork Sun Jan 21 05:32:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 764929 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCE613613A; Sun, 21 Jan 2024 05:32:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705815161; cv=none; b=s0CvEDSArPmvbzEGDamNm7PgJKVGOtQGHdPOKvPaM80ySypVPRSKfBhFxtY4BDpC8OOeOFLCFn3pigYEgm76xcpCDheXZ7pN9/PBhBcbiI7ZY2DuJAAywK1y9SNVCsPJtpaSBVdmOfwjOYsWRMBE4XBILjV6QtBF17lMQCaPVbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705815161; c=relaxed/simple; bh=AphfAL3cM0xZOhnH9SIZrKDesJmNNMtj5nIKD9faQ2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g4ZB26VM3Srf/nQFl4QSTzxICDXMqVfnpJm28P7s7EPdmW3XBPqrk0BBsuSsmA6wOzem3NbCsgJfifcWYrMLc2tKQ74OMDZUQOdg38nXNgpMvMpMVjrJgaPimoz5/dDbNZYlP+x5CdF1jz0ZmnOEq3jVi2s17pTvBFyZ8Ldt7vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Vd0tHpIP; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Vd0tHpIP" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-28be8ebcdc1so1191427a91.0; Sat, 20 Jan 2024 21:32:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705815159; x=1706419959; darn=vger.kernel.org; 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=ZEiAmvaeobj6IMpvm26ebe6qCNpZqbeBLm49Jnrvqx4=; b=Vd0tHpIPHcZSlwIeK9zVvj5vmvpP4UKWqm+LRjIpJMlwEcvvAKJhoFk/maxELaS+ZX cFk9RDiN2WP7RsDlWL9le9omonYUmHfMPGF4JgauQYKHBsjtB7sEljQhQCPeH4IMSYmX 9vwwkHXClq8BGCIQ66DFpQmghoS8HoQXAnF0ZF01NAzKPkyrabTw6JZE2ynSSA6pSbKs KygyHbsdFqHt1XrLKSN5vcH7fsVrnnrRDyeBQvV6cR95LdCdIA/yEap8RLeVvFPfOZBJ KyuxqTf7UCbA+bo/IW0XsTQgYS/ymOTNheLNB1KQWc2Gnhs3dhOtdRs7tpwxZEppf+Wr 3CxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705815159; x=1706419959; 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=ZEiAmvaeobj6IMpvm26ebe6qCNpZqbeBLm49Jnrvqx4=; b=UHr5aWexu/RBw08Dhs7PH2q+vQv5d3DFtiMI5gg6g8IBLQ+oBly3CUBKsN+Cfjooak BNX81jdXiuGawaM1IB9oSLR8f9xVh9gDaW+KBZ/iyFu2Q30NGUHU/4Pyh80JB2VvAwkr CkQ898ljP2dGjfXiqFJDqMbHdQsy21UgXBWaIJwsGmhMwofmAvkGMTK4I2JNJig/TOQh ZFPPtTdNs9WRY74aKKjZB6dj+XAXfk9s+Cb+cFIgcNm4tHN7dgo6NpN9o94fDEznyO/U 0n0LJ80iFS7bCoGN8NXi8f0R0j+zD3eipNj5zoViO5VyAWtGDAI65W6MIKN2gyxDNmgg i9UQ== X-Gm-Message-State: AOJu0YxBh5hpKVsM+lpN/ucnAVYKujJoVgXBzZt/QMGT27QFDUWEECO7 R2CXBNRov7lTMKf+c/vb/THKet45WEtvUYPEAAxQqyQ9R9qt8jmXT2zNNGNs X-Google-Smtp-Source: AGHT+IEtwf0VO/jX1V1D1Va5aahAVxhr1+Fz+ATwGT4IZFiGVqWIwqnCzyRuGk9PgwSzQoajiCLRLg== X-Received: by 2002:a17:90a:d390:b0:290:3e62:92ab with SMTP id q16-20020a17090ad39000b002903e6292abmr683818pju.29.1705815158650; Sat, 20 Jan 2024 21:32:38 -0800 (PST) Received: from dtor-ws.mtv.corp.google.com ([2620:15c:9d:2:b227:ab83:6b35:c967]) by smtp.gmail.com with ESMTPSA id mg7-20020a170903348700b001d69badff91sm5323978plb.148.2024.01.20.21.32.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 21:32:37 -0800 (PST) From: Dmitry Torokhov To: linux-input@vger.kernel.org, Dan Carpenter , Bartosz Golaszewski Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/3] Input: matrix_keypad - switch to using managed resources Date: Sat, 20 Jan 2024 21:32:30 -0800 Message-ID: <20240121053232.276968-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog In-Reply-To: <20240121053232.276968-1-dmitry.torokhov@gmail.com> References: <20240121053232.276968-1-dmitry.torokhov@gmail.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Switch the drivers to use managed resources (devm) to simplify error handling and remove the need to have remove() implementation. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 89 +++++++------------------- 1 file changed, 24 insertions(+), 65 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 44ef600b8f19..695c03e075b5 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -278,38 +278,41 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, /* initialized strobe lines as outputs, activated */ for (i = 0; i < pdata->num_col_gpios; i++) { - err = gpio_request(pdata->col_gpios[i], "matrix_kbd_col"); + err = devm_gpio_request(&pdev->dev, + pdata->col_gpios[i], "matrix_kbd_col"); if (err) { dev_err(&pdev->dev, "failed to request GPIO%d for COL%d\n", pdata->col_gpios[i], i); - goto err_free_cols; + return err; } gpio_direction_output(pdata->col_gpios[i], !pdata->active_low); } for (i = 0; i < pdata->num_row_gpios; i++) { - err = gpio_request(pdata->row_gpios[i], "matrix_kbd_row"); + err = devm_gpio_request(&pdev->dev, + pdata->row_gpios[i], "matrix_kbd_row"); if (err) { dev_err(&pdev->dev, "failed to request GPIO%d for ROW%d\n", pdata->row_gpios[i], i); - goto err_free_rows; + return err; } gpio_direction_input(pdata->row_gpios[i]); } if (pdata->clustered_irq > 0) { - err = request_any_context_irq(pdata->clustered_irq, + err = devm_request_any_context_irq(&pdev->dev, + pdata->clustered_irq, matrix_keypad_interrupt, pdata->clustered_irq_flags, "matrix-keypad", keypad); if (err < 0) { dev_err(&pdev->dev, "Unable to acquire clustered interrupt\n"); - goto err_free_rows; + return err; } keypad->row_irqs[0] = pdata->clustered_irq; @@ -322,10 +325,11 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, dev_err(&pdev->dev, "Unable to convert GPIO line %i to irq: %d\n", pdata->row_gpios[i], err); - goto err_free_irqs; + return err; } - err = request_any_context_irq(irq, + err = devm_request_any_context_irq(&pdev->dev, + irq, matrix_keypad_interrupt, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, @@ -334,7 +338,7 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, dev_err(&pdev->dev, "Unable to acquire interrupt for GPIO line %i\n", pdata->row_gpios[i]); - goto err_free_irqs; + return err; } keypad->row_irqs[i] = irq; @@ -345,36 +349,8 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, /* initialized as disabled - enabled by input->open */ disable_row_irqs(keypad); - return 0; - -err_free_irqs: - while (--i >= 0) - free_irq(keypad->row_irqs[i], keypad); - i = pdata->num_row_gpios; -err_free_rows: - while (--i >= 0) - gpio_free(pdata->row_gpios[i]); - i = pdata->num_col_gpios; -err_free_cols: - while (--i >= 0) - gpio_free(pdata->col_gpios[i]); - - return err; -} - -static void matrix_keypad_free_gpio(struct matrix_keypad *keypad) -{ - const struct matrix_keypad_platform_data *pdata = keypad->pdata; - int i; - - for (i = 0; i < keypad->num_row_irqs; i++) - free_irq(keypad->row_irqs[i], keypad); - - for (i = 0; i < pdata->num_row_gpios; i++) - gpio_free(pdata->row_gpios[i]); - for (i = 0; i < pdata->num_col_gpios; i++) - gpio_free(pdata->col_gpios[i]); + return 0; } #ifdef CONFIG_OF @@ -473,12 +449,13 @@ static int matrix_keypad_probe(struct platform_device *pdev) return -EINVAL; } - keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL); - input_dev = input_allocate_device(); - if (!keypad || !input_dev) { - err = -ENOMEM; - goto err_free_mem; - } + keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); + if (!keypad) + return -ENOMEM; + + input_dev = devm_input_allocate_device(&pdev->dev); + if (!input_dev) + return -ENOMEM; keypad->input_dev = input_dev; keypad->pdata = pdata; @@ -489,7 +466,6 @@ static int matrix_keypad_probe(struct platform_device *pdev) input_dev->name = pdev->name; input_dev->id.bustype = BUS_HOST; - input_dev->dev.parent = &pdev->dev; input_dev->open = matrix_keypad_start; input_dev->close = matrix_keypad_stop; @@ -499,7 +475,7 @@ static int matrix_keypad_probe(struct platform_device *pdev) NULL, input_dev); if (err) { dev_err(&pdev->dev, "failed to build keymap\n"); - goto err_free_mem; + return -ENOMEM; } if (!pdata->no_autorepeat) @@ -509,32 +485,16 @@ static int matrix_keypad_probe(struct platform_device *pdev) err = matrix_keypad_init_gpio(pdev, keypad); if (err) - goto err_free_mem; + return err; err = input_register_device(keypad->input_dev); if (err) - goto err_free_gpio; + return err; device_init_wakeup(&pdev->dev, pdata->wakeup); platform_set_drvdata(pdev, keypad); return 0; - -err_free_gpio: - matrix_keypad_free_gpio(keypad); -err_free_mem: - input_free_device(input_dev); - kfree(keypad); - return err; -} - -static void matrix_keypad_remove(struct platform_device *pdev) -{ - struct matrix_keypad *keypad = platform_get_drvdata(pdev); - - matrix_keypad_free_gpio(keypad); - input_unregister_device(keypad->input_dev); - kfree(keypad); } #ifdef CONFIG_OF @@ -547,7 +507,6 @@ MODULE_DEVICE_TABLE(of, matrix_keypad_dt_match); static struct platform_driver matrix_keypad_driver = { .probe = matrix_keypad_probe, - .remove_new = matrix_keypad_remove, .driver = { .name = "matrix-keypad", .pm = pm_sleep_ptr(&matrix_keypad_pm_ops),