From patchwork Mon Aug 5 01:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13753067 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 469A1C3DA64 for ; Mon, 5 Aug 2024 01:47:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 14FE9C4AF10; Mon, 5 Aug 2024 01:47:24 +0000 (UTC) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 24849C4AF0E for ; Mon, 5 Aug 2024 01:47:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 smtp.kernel.org 24849C4AF0E Authentication-Results: smtp.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fc566ac769so70991915ad.1 for ; Sun, 04 Aug 2024 18:47:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722822442; x=1723427242; darn=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=WwJabViyOwOqlsyuvl72Ko23CJ5ZXu78YeavmKzmGHg=; b=aqhwV5d42GRytTNkI7zbb7kAM7+Xfdf947jRFV//KYFa+UL7POYEiOezeze/S3OYEI eRPeTc07uSyNuclFKzCy90ffDMXZ5Dzg/LQn1ijLe0MVpsnk8XzCBS8hDJg9KIFu26eU zhxHPAGXTEYsGAQQbpIuax67c+67Hh6ODHFcfRxiwPB4o1P0aLJfE1MfqR6v7CIONasf I3blsPnYRb40MZfS2TjbKBOgfqboS/KXRv39frxRPw6bhDBln15kv1O1vEgpvi+ttnq5 y0pAn7YH6bXTQmryX+RVkW2h94uLY44EBolIM/+lOFqtYpyChnkS9uN+hupJVqb1+vhx ECIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722822442; x=1723427242; 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=WwJabViyOwOqlsyuvl72Ko23CJ5ZXu78YeavmKzmGHg=; b=BJDXL+/JJdpyyf46RdXFFUcy9BIAWVyTqSuDP2AQJZKmcPX6+hz2T3LKIwkp2ldxHB AaHnKvjCItixuNFRXCqUAyupVjZnzjOHtnR5NljKhoqEBcbH3+wcQ4uieu7f0GM89bs2 CHTgezaFD8ByAT0ngcXfNTeSYu+sF+gJZcXBKc/diGwu4fcPaXaXlDwbINE78+uNYndC o3TKvXCctm/Mr9saJTBhzUMqO86AKM8fr5+AGUf742oy39oLT+PvYi7Kxl3Qj4tkqF9A 0imeTjdd9tCiNl9WgWqnSvoS7PN43ca2dLXOfunvIcXP9dVTkuISn3F8SCLPQtiv/3hF /EwA== X-Forwarded-Encrypted: i=1; AJvYcCVyv+KuO1d3kQ1DDvY6Lq0qnm4Bi9ePek3os70NhMWsCuK1Ef7PblpTo0Y8eYEYx1hr6SNPq/05Rytq/7HB+g== X-Gm-Message-State: AOJu0YxVwtKxPHY9xA1iIN67pW1ULY91HN0fsAgPzUKyWK/6clpFht+k Ut8qHJc1MVBekp4jtkand6Kt2MYIpPoKo+kuhkxKHT8GANXjQOKH X-Google-Smtp-Source: AGHT+IGqwFPnuoOcmLqV0N/ujzd8JY77yP2Twv7LpGxD6AnhEF82wcYDFjWQijLX+wgx8uEDkpH7hg== X-Received: by 2002:a17:902:db0b:b0:1ff:6715:70f7 with SMTP id d9443c01a7336-1ff67158218mr47347265ad.28.1722822442416; Sun, 04 Aug 2024 18:47:22 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:22e4:17a:28a:7497]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59295790sm55836015ad.261.2024.08.04.18.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 18:47:22 -0700 (PDT) From: Dmitry Torokhov List-Id: To: Haojian Zhuang , Daniel Mack , Robert Jarzmik , Arnd Bergmann , Linus Walleij , soc@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 1/5] Input: matrix_keypad - remove support for clustered interrupt Date: Sun, 4 Aug 2024 18:47:04 -0700 Message-ID: <20240805014710.1961677-2-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog In-Reply-To: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> References: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 There are no users of this functionality in the mainline kernel (it was only available to boards using platform data and not device tree). Remove it to simplify the code. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 61 ++++++++++---------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 7a56f3d3aacd..604e90d13ed0 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -29,7 +29,6 @@ struct matrix_keypad { unsigned int row_shift; 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]; @@ -88,7 +87,7 @@ static void enable_row_irqs(struct matrix_keypad *keypad) { int i; - for (i = 0; i < keypad->num_row_irqs; i++) + for (i = 0; i < keypad->pdata->num_row_gpios; i++) enable_irq(keypad->row_irqs[i]); } @@ -96,7 +95,7 @@ static void disable_row_irqs(struct matrix_keypad *keypad) { int i; - for (i = 0; i < keypad->num_row_irqs; i++) + for (i = 0; i < keypad->pdata->num_row_gpios; i++) disable_irq_nosync(keypad->row_irqs[i]); } @@ -225,7 +224,8 @@ static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad) { int i; - for_each_clear_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) + for_each_clear_bit(i, keypad->wakeup_enabled_irqs, + keypad->pdata->num_row_gpios) if (enable_irq_wake(keypad->row_irqs[i]) == 0) __set_bit(i, keypad->wakeup_enabled_irqs); } @@ -234,7 +234,8 @@ static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad) { int i; - for_each_set_bit(i, keypad->wakeup_enabled_irqs, keypad->num_row_irqs) { + for_each_set_bit(i, keypad->wakeup_enabled_irqs, + keypad->pdata->num_row_gpios) { disable_irq_wake(keypad->row_irqs[i]); __clear_bit(i, keypad->wakeup_enabled_irqs); } @@ -302,48 +303,30 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, gpio_direction_input(pdata->row_gpios[i]); } - if (pdata->clustered_irq > 0) { + for (i = 0; i < pdata->num_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); + return err; + } + err = devm_request_any_context_irq(&pdev->dev, - pdata->clustered_irq, + irq, matrix_keypad_interrupt, - pdata->clustered_irq_flags, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING, "matrix-keypad", keypad); if (err < 0) { dev_err(&pdev->dev, - "Unable to acquire clustered interrupt\n"); + "Unable to acquire interrupt for GPIO line %i\n", + pdata->row_gpios[i]); return err; } - 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]); - if (irq < 0) { - err = irq; - dev_err(&pdev->dev, - "Unable to convert GPIO line %i to irq: %d\n", - pdata->row_gpios[i], err); - return err; - } - - err = devm_request_any_context_irq(&pdev->dev, - irq, - matrix_keypad_interrupt, - IRQF_TRIGGER_RISING | - IRQF_TRIGGER_FALLING, - "matrix-keypad", keypad); - if (err < 0) { - dev_err(&pdev->dev, - "Unable to acquire interrupt for GPIO line %i\n", - pdata->row_gpios[i]); - return err; - } - - keypad->row_irqs[i] = irq; - } - - keypad->num_row_irqs = pdata->num_row_gpios; + keypad->row_irqs[i] = irq; } /* initialized as disabled - enabled by input->open */ From patchwork Mon Aug 5 01:47:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13753069 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 836CFC3DA7F for ; Mon, 5 Aug 2024 01:47:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 74F16C4AF14; Mon, 5 Aug 2024 01:47:26 +0000 (UTC) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 8B791C4AF12 for ; Mon, 5 Aug 2024 01:47:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 smtp.kernel.org 8B791C4AF12 Authentication-Results: smtp.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1ff3d5c6e9eso42743885ad.1 for ; Sun, 04 Aug 2024 18:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722822444; x=1723427244; darn=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=3W9Xny5Oe2jyjvAS76xpniX/sLkXGO8PpSiALjSSUIs=; b=jTW/CK9Rgk6jfcoZthBrH1bl1wgeShtXPha3ueADP2K8GmmxbMFSILlN7Q24gLmTDN +iaSlH66GrJouGW/IrYmRKOLr0GUT/8U5/vVit7QKI98AGkBB4Tp6z+41JkRxX6ixEDx wlkiCn2n8L2epxjJWs1z+FMrR+6WseW1tJzOcXpA5ZU/Me9WONr9H6JXoPLCRTkxWcC0 uOd84yvmxd9ojvbEiT02F9GMCERWhGlZtnsXVIavOaYgKATjn4I3qybhUrOzNJ7RaomB LY+tG4Tuhe4bf38dKqtEDa1tsc15p712SpmPSsHPRF62MZNNrrz4pHzV7hd+5svx+MbT SYzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722822444; x=1723427244; 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=3W9Xny5Oe2jyjvAS76xpniX/sLkXGO8PpSiALjSSUIs=; b=nOgmRg6w4YeURr1qZO9qTd0fREDTIaigDo7v1T6ZFqExax9Yg/sRRl4XTh2mXug+1O iP6mt/UBvupzXB/F1NE1KZLKIsH7cW/FzOQ2Qrblw1K/4Pro7ZtTSOrhJR8uY78Mf2Ie WlFSaleF8X88Jf8iYDyxOV4tQxoCMB64rE4MISCgrPcOPMm/dcUTBdjVU62lHS8XaYt1 wdmu+Vq7Y+b0nPM1c0r+0BDcCpfrrT21ir72iE217BNW0yVqYPWQVqBw8EWGOXoBopqk 5JaoiQEPtyN+AOg0cDxBZ1xvHmo0lWXGi0oRco6wpk3Ik3pW4n0wpKr2fo8fMQu/IZqy nwlw== X-Forwarded-Encrypted: i=1; AJvYcCXVlDQzlWfGpoLQaoqpzMopqsIAHa+j7/3heOVTliFw2iXqKtM3e2OLm8n5kvY+gVYO6qFOKHo8WAGU7WnwCQ== X-Gm-Message-State: AOJu0Yz80Y5fOY423Ay8FrmshLaINVrUpRs9FXBHcQS3PVNnJ1AO+KEm zJJ1Um+p7XqPtlid5cG4xlGn+Wm9vF9fRy9cCA7dUCDfLX9gUm6M X-Google-Smtp-Source: AGHT+IG2qk2UX76WiKnUEfoLNtj9w3mHbdNpAlFnbpU8lmTUrz8S1fXH3OJw5hl3xcahnItIgN3FOQ== X-Received: by 2002:a17:902:b70d:b0:1ff:3b0f:d5e2 with SMTP id d9443c01a7336-1ff5737e3abmr89071635ad.32.1722822443699; Sun, 04 Aug 2024 18:47:23 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:22e4:17a:28a:7497]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59295790sm55836015ad.261.2024.08.04.18.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 18:47:23 -0700 (PDT) From: Dmitry Torokhov List-Id: To: Haojian Zhuang , Daniel Mack , Robert Jarzmik , Arnd Bergmann , Linus Walleij , soc@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 2/5] Input: matrix_keypad - switch to gpiod API and generic device properties Date: Sun, 4 Aug 2024 18:47:05 -0700 Message-ID: <20240805014710.1961677-3-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog In-Reply-To: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> References: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 gpiod API and generic device properties work with software nodes and static properties, which will allow removing platform data support from the driver, simplifying and streamlining the code. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 341 ++++++++++++++----------- 1 file changed, 185 insertions(+), 156 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 604e90d13ed0..5f7e6f27e9c5 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -17,17 +17,26 @@ #include #include #include +#include #include #include #include -#include -#include struct matrix_keypad { - const struct matrix_keypad_platform_data *pdata; struct input_dev *input_dev; unsigned int row_shift; + unsigned int col_scan_delay_us; + /* key debounce interval in milli-second */ + unsigned int debounce_ms; + bool drive_inactive_cols; + + struct gpio_desc *row_gpios[MATRIX_MAX_ROWS]; + unsigned int num_row_gpios; + + struct gpio_desc *col_gpios[MATRIX_MAX_ROWS]; + unsigned int num_col_gpios; + unsigned int row_irqs[MATRIX_MAX_ROWS]; DECLARE_BITMAP(wakeup_enabled_irqs, MATRIX_MAX_ROWS); @@ -44,50 +53,43 @@ struct matrix_keypad { * columns. In that case it is configured here to be input, otherwise it is * driven with the inactive value. */ -static void __activate_col(const struct matrix_keypad_platform_data *pdata, - int col, bool on) +static void __activate_col(struct matrix_keypad *keypad, int col, bool on) { - bool level_on = !pdata->active_low; - if (on) { - gpio_direction_output(pdata->col_gpios[col], level_on); + gpiod_direction_output(keypad->col_gpios[col], 1); } else { - gpio_set_value_cansleep(pdata->col_gpios[col], !level_on); - if (!pdata->drive_inactive_cols) - gpio_direction_input(pdata->col_gpios[col]); + gpiod_set_value_cansleep(keypad->col_gpios[col], 0); + if (!keypad->drive_inactive_cols) + gpiod_direction_input(keypad->col_gpios[col]); } } -static void activate_col(const struct matrix_keypad_platform_data *pdata, - int col, bool on) +static void activate_col(struct matrix_keypad *keypad, int col, bool on) { - __activate_col(pdata, col, on); + __activate_col(keypad, col, on); - if (on && pdata->col_scan_delay_us) - udelay(pdata->col_scan_delay_us); + if (on && keypad->col_scan_delay_us) + udelay(keypad->col_scan_delay_us); } -static void activate_all_cols(const struct matrix_keypad_platform_data *pdata, - bool on) +static void activate_all_cols(struct matrix_keypad *keypad, bool on) { int col; - for (col = 0; col < pdata->num_col_gpios; col++) - __activate_col(pdata, col, on); + for (col = 0; col < keypad->num_col_gpios; col++) + __activate_col(keypad, col, on); } -static bool row_asserted(const struct matrix_keypad_platform_data *pdata, - int row) +static bool row_asserted(struct matrix_keypad *keypad, int row) { - return gpio_get_value_cansleep(pdata->row_gpios[row]) ? - !pdata->active_low : pdata->active_low; + return gpiod_get_value_cansleep(keypad->row_gpios[row]); } static void enable_row_irqs(struct matrix_keypad *keypad) { int i; - for (i = 0; i < keypad->pdata->num_row_gpios; i++) + for (i = 0; i < keypad->num_row_gpios; i++) enable_irq(keypad->row_irqs[i]); } @@ -95,7 +97,7 @@ static void disable_row_irqs(struct matrix_keypad *keypad) { int i; - for (i = 0; i < keypad->pdata->num_row_gpios; i++) + for (i = 0; i < keypad->num_row_gpios; i++) disable_irq_nosync(keypad->row_irqs[i]); } @@ -108,39 +110,38 @@ static void matrix_keypad_scan(struct work_struct *work) container_of(work, struct matrix_keypad, work.work); struct input_dev *input_dev = keypad->input_dev; const unsigned short *keycodes = input_dev->keycode; - const struct matrix_keypad_platform_data *pdata = keypad->pdata; uint32_t new_state[MATRIX_MAX_COLS]; int row, col, code; /* de-activate all columns for scanning */ - activate_all_cols(pdata, false); + activate_all_cols(keypad, false); memset(new_state, 0, sizeof(new_state)); - for (row = 0; row < pdata->num_row_gpios; row++) - gpio_direction_input(pdata->row_gpios[row]); + for (row = 0; row < keypad->num_row_gpios; row++) + gpiod_direction_input(keypad->row_gpios[row]); /* assert each column and read the row status out */ - for (col = 0; col < pdata->num_col_gpios; col++) { + for (col = 0; col < keypad->num_col_gpios; col++) { - activate_col(pdata, col, true); + activate_col(keypad, col, true); - for (row = 0; row < pdata->num_row_gpios; row++) + for (row = 0; row < keypad->num_row_gpios; row++) new_state[col] |= - row_asserted(pdata, row) ? (1 << row) : 0; + row_asserted(keypad, row) ? BIT(row) : 0; - activate_col(pdata, col, false); + activate_col(keypad, col, false); } - for (col = 0; col < pdata->num_col_gpios; col++) { + for (col = 0; col < keypad->num_col_gpios; col++) { uint32_t bits_changed; bits_changed = keypad->last_key_state[col] ^ new_state[col]; if (bits_changed == 0) continue; - for (row = 0; row < pdata->num_row_gpios; row++) { - if ((bits_changed & (1 << row)) == 0) + for (row = 0; row < keypad->num_row_gpios; row++) { + if (!(bits_changed & BIT(row))) continue; code = MATRIX_SCAN_CODE(row, col, keypad->row_shift); @@ -154,7 +155,7 @@ static void matrix_keypad_scan(struct work_struct *work) memcpy(keypad->last_key_state, new_state, sizeof(new_state)); - activate_all_cols(pdata, true); + activate_all_cols(keypad, true); /* Enable IRQs again */ spin_lock_irq(&keypad->lock); @@ -181,7 +182,7 @@ static irqreturn_t matrix_keypad_interrupt(int irq, void *id) disable_row_irqs(keypad); keypad->scan_pending = true; schedule_delayed_work(&keypad->work, - msecs_to_jiffies(keypad->pdata->debounce_ms)); + msecs_to_jiffies(keypad->debounce_ms)); out: spin_unlock_irqrestore(&keypad->lock, flags); @@ -225,7 +226,7 @@ static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad) int i; for_each_clear_bit(i, keypad->wakeup_enabled_irqs, - keypad->pdata->num_row_gpios) + keypad->num_row_gpios) if (enable_irq_wake(keypad->row_irqs[i]) == 0) __set_bit(i, keypad->wakeup_enabled_irqs); } @@ -235,7 +236,7 @@ static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad) int i; for_each_set_bit(i, keypad->wakeup_enabled_irqs, - keypad->pdata->num_row_gpios) { + keypad->num_row_gpios) { disable_irq_wake(keypad->row_irqs[i]); __clear_bit(i, keypad->wakeup_enabled_irqs); } @@ -270,11 +271,14 @@ static int matrix_keypad_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(matrix_keypad_pm_ops, matrix_keypad_suspend, matrix_keypad_resume); -static int matrix_keypad_init_gpio(struct platform_device *pdev, - struct matrix_keypad *keypad) +static int matrix_keypad_init_pdata_gpio(struct platform_device *pdev, + const struct matrix_keypad_platform_data *pdata, + struct matrix_keypad *keypad) { - const struct matrix_keypad_platform_data *pdata = keypad->pdata; - int i, irq, err; + int i, err; + + keypad->num_col_gpios = pdata->num_col_gpios; + keypad->num_row_gpios = pdata->num_row_gpios; /* initialized strobe lines as outputs, activated */ for (i = 0; i < pdata->num_col_gpios; i++) { @@ -287,7 +291,12 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, return err; } - gpio_direction_output(pdata->col_gpios[i], !pdata->active_low); + keypad->col_gpios[i] = gpio_to_desc(pdata->col_gpios[i]); + + if (pdata->active_low ^ gpiod_is_active_low(keypad->col_gpios[i])) + gpiod_toggle_active_low(keypad->col_gpios[i]); + + gpiod_direction_output(keypad->col_gpios[i], 1); } for (i = 0; i < pdata->num_row_gpios; i++) { @@ -300,137 +309,125 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev, return err; } - gpio_direction_input(pdata->row_gpios[i]); - } - - for (i = 0; i < pdata->num_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); - return err; - } + keypad->row_gpios[i] = gpio_to_desc(pdata->row_gpios[i]); - err = devm_request_any_context_irq(&pdev->dev, - irq, - matrix_keypad_interrupt, - IRQF_TRIGGER_RISING | - IRQF_TRIGGER_FALLING, - "matrix-keypad", keypad); - if (err < 0) { - dev_err(&pdev->dev, - "Unable to acquire interrupt for GPIO line %i\n", - pdata->row_gpios[i]); - return err; - } + if (pdata->active_low ^ gpiod_is_active_low(keypad->row_gpios[i])) + gpiod_toggle_active_low(keypad->row_gpios[i]); - keypad->row_irqs[i] = irq; + gpiod_direction_input(keypad->row_gpios[i]); } - /* initialized as disabled - enabled by input->open */ - disable_row_irqs(keypad); - return 0; } -#ifdef CONFIG_OF -static struct matrix_keypad_platform_data * -matrix_keypad_parse_dt(struct device *dev) +static int matrix_keypad_init_gpio(struct platform_device *pdev, + struct matrix_keypad *keypad) { - struct matrix_keypad_platform_data *pdata; - struct device_node *np = dev->of_node; - unsigned int *gpios; - int ret, i, nrow, ncol; - - if (!np) { - dev_err(dev, "device lacks DT data\n"); - return ERR_PTR(-ENODEV); - } - - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); - if (!pdata) { - dev_err(dev, "could not allocate memory for platform data\n"); - return ERR_PTR(-ENOMEM); - } + bool active_low; + int nrow, ncol; + int err; + int i; - pdata->num_row_gpios = nrow = gpiod_count(dev, "row"); - pdata->num_col_gpios = ncol = gpiod_count(dev, "col"); + nrow = gpiod_count(&pdev->dev, "row"); + ncol = gpiod_count(&pdev->dev, "col"); if (nrow < 0 || ncol < 0) { - dev_err(dev, "number of keypad rows/columns not specified\n"); - return ERR_PTR(-EINVAL); + dev_err(&pdev->dev, "missing row or column GPIOs\n"); + return -EINVAL; } - pdata->no_autorepeat = of_property_read_bool(np, "linux,no-autorepeat"); + keypad->num_row_gpios = nrow; + keypad->num_col_gpios = ncol; - pdata->wakeup = of_property_read_bool(np, "wakeup-source") || - of_property_read_bool(np, "linux,wakeup"); /* legacy */ + active_low = device_property_read_bool(&pdev->dev, "gpio-activelow"); - pdata->active_low = of_property_read_bool(np, "gpio-activelow"); + /* initialize strobe lines as outputs, activated */ + for (i = 0; i < keypad->num_col_gpios; i++) { + keypad->col_gpios[i] = devm_gpiod_get_index(&pdev->dev, "col", + i, GPIOD_ASIS); + err = PTR_ERR_OR_ZERO(keypad->col_gpios[i]); + if (err) { + dev_err(&pdev->dev, + "failed to request GPIO for COL%d: %d\n", + i, err); + return err; + } - pdata->drive_inactive_cols = - of_property_read_bool(np, "drive-inactive-cols"); + gpiod_set_consumer_name(keypad->col_gpios[i], "matrix_kbd_col"); - of_property_read_u32(np, "debounce-delay-ms", &pdata->debounce_ms); - of_property_read_u32(np, "col-scan-delay-us", - &pdata->col_scan_delay_us); + if (active_low ^ gpiod_is_active_low(keypad->col_gpios[i])) + gpiod_toggle_active_low(keypad->col_gpios[i]); - gpios = devm_kcalloc(dev, - pdata->num_row_gpios + pdata->num_col_gpios, - sizeof(unsigned int), - GFP_KERNEL); - if (!gpios) { - dev_err(dev, "could not allocate memory for gpios\n"); - return ERR_PTR(-ENOMEM); + gpiod_direction_output(keypad->col_gpios[i], 1); } - for (i = 0; i < nrow; i++) { - ret = of_get_named_gpio(np, "row-gpios", i); - if (ret < 0) - return ERR_PTR(ret); - gpios[i] = ret; - } + for (i = 0; i < keypad->num_row_gpios; i++) { + keypad->row_gpios[i] = devm_gpiod_get_index(&pdev->dev, "row", + i, GPIOD_IN); + err = PTR_ERR_OR_ZERO(keypad->row_gpios[i]); + if (err) { + dev_err(&pdev->dev, + "failed to request GPIO for ROW%d: %d\n", + i, err); + return err; + } - for (i = 0; i < ncol; i++) { - ret = of_get_named_gpio(np, "col-gpios", i); - if (ret < 0) - return ERR_PTR(ret); - gpios[nrow + i] = ret; - } + gpiod_set_consumer_name(keypad->row_gpios[i], "matrix_kbd_row"); - pdata->row_gpios = gpios; - pdata->col_gpios = &gpios[pdata->num_row_gpios]; + if (active_low ^ gpiod_is_active_low(keypad->row_gpios[i])) + gpiod_toggle_active_low(keypad->row_gpios[i]); + } - return pdata; + return 0; } -#else -static inline struct matrix_keypad_platform_data * -matrix_keypad_parse_dt(struct device *dev) + +static int matrix_keypad_setup_interrupts(struct platform_device *pdev, + struct matrix_keypad *keypad) { - dev_err(dev, "no platform data defined\n"); + int err; + int irq; + int i; + + for (i = 0; i < keypad->num_row_gpios; i++) { + irq = gpiod_to_irq(keypad->row_gpios[i]); + if (irq < 0) { + err = irq; + dev_err(&pdev->dev, + "Unable to convert GPIO line %i to irq: %d\n", + i, err); + return err; + } + + err = devm_request_any_context_irq(&pdev->dev, irq, + matrix_keypad_interrupt, + IRQF_TRIGGER_RISING | + IRQF_TRIGGER_FALLING, + "matrix-keypad", keypad); + if (err < 0) { + dev_err(&pdev->dev, + "Unable to acquire interrupt for row %i: %d\n", + i, err); + return err; + } + + keypad->row_irqs[i] = irq; + } - return ERR_PTR(-EINVAL); + /* initialized as disabled - enabled by input->open */ + disable_row_irqs(keypad); + + return 0; } -#endif static int matrix_keypad_probe(struct platform_device *pdev) { - const struct matrix_keypad_platform_data *pdata; + const struct matrix_keypad_platform_data *pdata = + dev_get_platdata(&pdev->dev); struct matrix_keypad *keypad; struct input_dev *input_dev; + bool autorepeat; + bool wakeup; int err; - pdata = dev_get_platdata(&pdev->dev); - if (!pdata) { - pdata = matrix_keypad_parse_dt(&pdev->dev); - if (IS_ERR(pdata)) - return PTR_ERR(pdata); - } else if (!pdata->keymap_data) { - dev_err(&pdev->dev, "no keymap data defined\n"); - return -EINVAL; - } - keypad = devm_kzalloc(&pdev->dev, sizeof(*keypad), GFP_KERNEL); if (!keypad) return -ENOMEM; @@ -440,40 +437,72 @@ static int matrix_keypad_probe(struct platform_device *pdev) return -ENOMEM; keypad->input_dev = input_dev; - keypad->pdata = pdata; - keypad->row_shift = get_count_order(pdata->num_col_gpios); keypad->stopped = true; INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan); spin_lock_init(&keypad->lock); + keypad->drive_inactive_cols = + device_property_read_bool(&pdev->dev, "drive-inactive-cols"); + device_property_read_u32(&pdev->dev, "debounce-delay-ms", + &keypad->debounce_ms); + device_property_read_u32(&pdev->dev, "col-scan-delay-us", + &keypad->col_scan_delay_us); + + if (pdata) { + keypad->col_scan_delay_us = pdata->col_scan_delay_us; + keypad->debounce_ms = pdata->debounce_ms; + keypad->drive_inactive_cols = pdata->drive_inactive_cols; + } + + if (pdata) + err = matrix_keypad_init_pdata_gpio(pdev, pdata, keypad); + else + err = matrix_keypad_init_gpio(pdev, keypad); + if (err) + return err; + + keypad->row_shift = get_count_order(keypad->num_col_gpios); + + err = matrix_keypad_setup_interrupts(pdev, keypad); + if (err) + return err; + input_dev->name = pdev->name; input_dev->id.bustype = BUS_HOST; input_dev->open = matrix_keypad_start; input_dev->close = matrix_keypad_stop; - err = matrix_keypad_build_keymap(pdata->keymap_data, NULL, - pdata->num_row_gpios, - pdata->num_col_gpios, + err = matrix_keypad_build_keymap(pdata ? pdata->keymap_data : NULL, + NULL, + keypad->num_row_gpios, + keypad->num_col_gpios, NULL, input_dev); if (err) { dev_err(&pdev->dev, "failed to build keymap\n"); return -ENOMEM; } - if (!pdata->no_autorepeat) + autorepeat = !device_property_read_bool(&pdev->dev, + "linux,no-autorepeat"); + if (autorepeat && pdata->no_autorepeat) + autorepeat = false; + if (autorepeat) __set_bit(EV_REP, input_dev->evbit); + input_set_capability(input_dev, EV_MSC, MSC_SCAN); input_set_drvdata(input_dev, keypad); - err = matrix_keypad_init_gpio(pdev, keypad); - if (err) - return err; - err = input_register_device(keypad->input_dev); if (err) return err; - device_init_wakeup(&pdev->dev, pdata->wakeup); + wakeup = device_property_read_bool(&pdev->dev, "wakeup-source") || + /* legacy */ + device_property_read_bool(&pdev->dev, "linux,wakeup"); + if (!wakeup && pdata) + wakeup = pdata->wakeup; + device_init_wakeup(&pdev->dev, wakeup); + platform_set_drvdata(pdev, keypad); return 0; From patchwork Mon Aug 5 01:47:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13753068 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E2D2C52D6D for ; Mon, 5 Aug 2024 01:47:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 0D306C32786; Mon, 5 Aug 2024 01:47:27 +0000 (UTC) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id C010AC4AF0E for ; Mon, 5 Aug 2024 01:47:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 smtp.kernel.org C010AC4AF0E Authentication-Results: smtp.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1fec34f94abso77364875ad.2 for ; Sun, 04 Aug 2024 18:47:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722822445; x=1723427245; darn=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=5KT5OQ6GzPXvDFTLkEAc2lVR09Idrwl4z6UvcUd1WRM=; b=XFrxTSN+QI6whPseWLYFdSNFQEsWYqXLw8noguTeTNZ6kSRwp9VX2BxhDMUzQmVU3x qibtXzbHbkNLBdIZJEQRsXzsBlbOSQOhBT6+LNICXq5JU5QLSvsRUllV3vsqH/jODO0k 90/DKW63ArhGCzU7qCvalp+R+q2eaYldzOTLhHTZ9izGXNtOGlup6C69LciHeXMC7Q/H VtwuAor/eu7WycSEliBCLVYY4VQy7hZjrzKAITmTo3TS6AVT7kIjpn385F2PGv9sAcIk FBMY9rQ2WByXXtfaK0LniPEzYA1/TsJBRrVLXAvIr2QhKhDs5qUKJr65qRyM6twji8cg 47Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722822445; x=1723427245; 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=5KT5OQ6GzPXvDFTLkEAc2lVR09Idrwl4z6UvcUd1WRM=; b=KroFqo5bn1g4wKOiX29sn4vT/I4gQ8J8iBL5kzwUrudUa0Rtve2ZMTvReVwuNb1L+J 5u8ctlqEjsLXzfdwCpLMQRNfloH1JH7uPIja+hvbx2ogI79tV8KnYm2pM8Y9DMMjajWg 2TC1rhEK1Xsjbi4JdfvXvYaMCMcUUoOvVYPU/Pb8tsq/QH+VuEcsCD+yyFgqSYkJYhZH +KZN7LU9j5gGoy9euFSJGrJVSTi8snhs0Xv9NoSaHlfNCbWDiZCuZMtzVJwE9K/c+SC8 EOR9bW2SJQcFW/YzkM6babUF2TfesSVU2lYHrXE7mpcKU73ZeUGy8VImOSWh93ilwVzU QnuQ== X-Forwarded-Encrypted: i=1; AJvYcCUmJtq6M1UpSD9tUKPd8eeFIzbF31JMSGVoUkrpVt7jlPZCUhxCnOudbpEEB83OUywFvfiOukVs7xHH5oQNwQ== X-Gm-Message-State: AOJu0Ywo5j355b2B1KO1rfM/JmQQOHho6S376fJPcj/EcX90AWyahawt hCV1RdyvGcSpY8wgOhiQYns6+6m3R5t5yB/8RQK4Bqq5PrXZIR7T X-Google-Smtp-Source: AGHT+IGrPevOGrlhiIh2ypAJGRzfsgFKi7VmSIU2ZX7hVG5vsny8HwZs2H2+Vz3F41zi1kTLTuMLEw== X-Received: by 2002:a17:902:d505:b0:1ff:49a0:46b1 with SMTP id d9443c01a7336-1ff5722e7abmr106827945ad.6.1722822444951; Sun, 04 Aug 2024 18:47:24 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:22e4:17a:28a:7497]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59295790sm55836015ad.261.2024.08.04.18.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 18:47:24 -0700 (PDT) From: Dmitry Torokhov List-Id: To: Haojian Zhuang , Daniel Mack , Robert Jarzmik , Arnd Bergmann , Linus Walleij , soc@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 3/5] ARM: spitz: Use software nodes/properties for the GPIO-driven buttons Date: Sun, 4 Aug 2024 18:47:06 -0700 Message-ID: <20240805014710.1961677-4-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog In-Reply-To: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> References: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Convert the Spitz to use software nodes and static properties to describe GPIOs for the GPIO-driven buttons. Signed-off-by: Dmitry Torokhov --- arch/arm/mach-pxa/spitz.c | 99 +++++++++++++++++++++++++++------------ 1 file changed, 68 insertions(+), 31 deletions(-) diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c index 452bf7aac1fa..9a7dc7b8676d 100644 --- a/arch/arm/mach-pxa/spitz.c +++ b/arch/arm/mach-pxa/spitz.c @@ -419,45 +419,82 @@ static inline void spitz_mkp_init(void) {} * GPIO keys ******************************************************************************/ #if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) -static struct gpio_keys_button spitz_gpio_keys[] = { - { - .type = EV_PWR, - .code = KEY_SUSPEND, - .gpio = SPITZ_GPIO_ON_KEY, - .desc = "On Off", - .wakeup = 1, - }, - /* Two buttons detecting the lid state */ - { - .type = EV_SW, - .code = 0, - .gpio = SPITZ_GPIO_SWA, - .desc = "Display Down", - }, - { - .type = EV_SW, - .code = 1, - .gpio = SPITZ_GPIO_SWB, - .desc = "Lid Closed", - }, +static const struct software_node spitz_gpio_keys_node = { + .name = "spitz-gpio-keys", }; -static struct gpio_keys_platform_data spitz_gpio_keys_platform_data = { - .buttons = spitz_gpio_keys, - .nbuttons = ARRAY_SIZE(spitz_gpio_keys), +static const struct property_entry spitz_suspend_key_props[] = { + PROPERTY_ENTRY_U32("linux,input-type", EV_PWR), + PROPERTY_ENTRY_U32("linux,code", KEY_SUSPEND), + PROPERTY_ENTRY_GPIO("gpios", &pxa2xx_gpiochip_node, + SPITZ_GPIO_ON_KEY, GPIO_ACTIVE_HIGH), + PROPERTY_ENTRY_STRING("label", "On Off"), + PROPERTY_ENTRY_BOOL("wakeup-source"), + { } }; -static struct platform_device spitz_gpio_keys_device = { - .name = "gpio-keys", - .id = -1, - .dev = { - .platform_data = &spitz_gpio_keys_platform_data, - }, +static const struct software_node spitz_suspend_key_node = { + .parent = &spitz_gpio_keys_node, + .properties = spitz_suspend_key_props, +}; + +static const struct property_entry spitz_sw1_props[] = { + PROPERTY_ENTRY_U32("linux,input-type", EV_SW), + PROPERTY_ENTRY_U32("linux,code", 0), + PROPERTY_ENTRY_GPIO("gpios", &pxa2xx_gpiochip_node, + SPITZ_GPIO_SWA, GPIO_ACTIVE_HIGH), + PROPERTY_ENTRY_STRING("label", "Display Down"), + { } +}; + +static const struct software_node spitz_sw1_node = { + .parent = &spitz_gpio_keys_node, + .properties = spitz_sw1_props, +}; + +static const struct property_entry spitz_sw2_props[] = { + PROPERTY_ENTRY_U32("linux,input-type", EV_SW), + PROPERTY_ENTRY_U32("linux,code", 1), + PROPERTY_ENTRY_GPIO("gpios", &pxa2xx_gpiochip_node, + SPITZ_GPIO_SWB, GPIO_ACTIVE_HIGH), + PROPERTY_ENTRY_STRING("label", "Lid Closed"), + { } +}; + +static const struct software_node spitz_sw2_node = { + .parent = &spitz_gpio_keys_node, + .properties = spitz_sw2_props, +}; + +static const struct software_node *spitz_gpio_keys_swnodes[] = { + &spitz_gpio_keys_node, + &spitz_suspend_key_node, + &spitz_sw1_node, + &spitz_sw2_node, + NULL }; static void __init spitz_keys_init(void) { - platform_device_register(&spitz_gpio_keys_device); + struct platform_device_info keys_info = { + .name = "gpio-keys", + .id = PLATFORM_DEVID_NONE, + }; + struct platform_device *pd; + int err; + + err = software_node_register_node_group(spitz_gpio_keys_swnodes); + if (err) { + pr_err("failed to register gpio-keys software nodes: %d\n", err); + return; + } + + keys_info.fwnode = software_node_fwnode(&spitz_gpio_keys_node); + + pd = platform_device_register_full(&keys_info); + err = PTR_ERR_OR_ZERO(pd); + if (err) + pr_err("failed to create gpio-keys device: %d\n", err); } #else static inline void spitz_keys_init(void) {} From patchwork Mon Aug 5 01:47:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13753070 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24466C3DA64 for ; Mon, 5 Aug 2024 01:47:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 0515AC4AF0B; Mon, 5 Aug 2024 01:47:28 +0000 (UTC) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 1936DC4AF0C for ; Mon, 5 Aug 2024 01:47:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 smtp.kernel.org 1936DC4AF0C Authentication-Results: smtp.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1fc49c0aaffso72670635ad.3 for ; Sun, 04 Aug 2024 18:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722822446; x=1723427246; darn=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=y2fTMTU2sCnO518NONvI840diOGxlwU3sQIVaxycmPg=; b=Hzm7XHlgTXUPjIfMZvafJdaOClXamEYoOPUq/PcqYZ8irvq8/f/yEIRjW+N5B2zeVZ WoJoaKSSwwJJV3UhYVw20RixYleM5v1BVmwI2slsDtuUJ5K9GdqU9IprOT7TDFUyrnsx 3Xo89OnxBUGD858rxdpNLgdK/Gog5RWDZ8tyPEzW3e01FQhTaMmOJmaYQfc8dxrWciLl ODIYigW+d6nrQvWv1FhR6n2YMIvqmOgKvSHYEhj4njKwbi8EjMVaUAqH1/5ApAKvm8o0 oKQJ1rSPPcPA8o6k6oBBOC0wcEDwIoVOQNYMQApTxrYw5DOVxF8z+gHMI5QKmujnEEe4 jlrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722822446; x=1723427246; 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=y2fTMTU2sCnO518NONvI840diOGxlwU3sQIVaxycmPg=; b=e8jySXyMehgfLZmM7Zzp/zaPeVPV7Jt9BBipO9B9Gl6+18QfrUNlS8GUJgsSOS3Z17 Or/twKibOAZjw9BNSomVbhUeINLrjqKePZ4en6JJz7LeTW+8t1Ve4vF2OeWojr+MYk/Z ghFOPWbR6PY+GPHU64HYLK+6xFyOE7nnikTqbil9rQ9eMgqkVpxl3rsQZTFpXp0xO8OB /+s+t9Ozr7ewnv4jKvKaALnk8wgLXFsu49Dsf5SrXoljBkF5oict+wKljoTX8uY7vIsB xsOcOmNNltLkpqipR462dlkQ3J1Wj3oxfeGxgTAbOBrT/AQxqwuFLBUwF8z6p94xJ4Pt sMHA== X-Forwarded-Encrypted: i=1; AJvYcCUlBQQn0DpMgiT6L/pqmtPLHWLc2xSRvtrfy16sSRrSFDTblraBrURMLRJaVQN8v6FGzDGoUe08m5BtXx+MgA== X-Gm-Message-State: AOJu0Yz/1Yg951gI4ukUNaCAD/tXcTiDHlzB8PE+WifmNRnaNMlfKWAF jxOu/Ez2v4+/vU8X5O6tm2XGSBlElSO0351qvfWFWR8cFJ8H5rxY X-Google-Smtp-Source: AGHT+IFGvfv0qGcuu0s9hpraRVdX+4qEf2sPdEvVVkHNnRbbklmFC1Z3IJaCt/qLGORFLVGSXNLLxw== X-Received: by 2002:a17:902:d2ce:b0:1f6:f298:e50 with SMTP id d9443c01a7336-1ff574e697cmr111650735ad.58.1722822446358; Sun, 04 Aug 2024 18:47:26 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:22e4:17a:28a:7497]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59295790sm55836015ad.261.2024.08.04.18.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 18:47:25 -0700 (PDT) From: Dmitry Torokhov List-Id: To: Haojian Zhuang , Daniel Mack , Robert Jarzmik , Arnd Bergmann , Linus Walleij , soc@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 4/5] ARM: spitz: Use software nodes/properties for the matrix keypad Date: Sun, 4 Aug 2024 18:47:07 -0700 Message-ID: <20240805014710.1961677-5-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog In-Reply-To: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> References: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 Convert the Spitz to use software nodes and static properties to describe GPIOs and other parameters of its matrix keypad. Signed-off-by: Dmitry Torokhov --- arch/arm/mach-pxa/spitz.c | 64 +++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c index 9a7dc7b8676d..690596f36979 100644 --- a/arch/arm/mach-pxa/spitz.c +++ b/arch/arm/mach-pxa/spitz.c @@ -378,38 +378,56 @@ static const uint32_t spitz_keymap[] = { KEY(6, 8, KEY_RIGHT), }; -static const struct matrix_keymap_data spitz_keymap_data = { - .keymap = spitz_keymap, - .keymap_size = ARRAY_SIZE(spitz_keymap), +static const struct software_node_ref_args spitz_mkp_row_gpios[] = { + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 12, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 17, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 91, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 34, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 36, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 38, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 39, GPIO_ACTIVE_HIGH), }; -static const uint32_t spitz_row_gpios[] = - { 12, 17, 91, 34, 36, 38, 39 }; -static const uint32_t spitz_col_gpios[] = - { 88, 23, 24, 25, 26, 27, 52, 103, 107, 108, 114 }; - -static struct matrix_keypad_platform_data spitz_mkp_pdata = { - .keymap_data = &spitz_keymap_data, - .row_gpios = spitz_row_gpios, - .col_gpios = spitz_col_gpios, - .num_row_gpios = ARRAY_SIZE(spitz_row_gpios), - .num_col_gpios = ARRAY_SIZE(spitz_col_gpios), - .col_scan_delay_us = 10, - .debounce_ms = 10, - .wakeup = 1, +static const struct software_node_ref_args spitz_mkp_col_gpios[] = { + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 88, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 23, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 24, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 25, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 26, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 27, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 52, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 103, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 107, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 108, GPIO_ACTIVE_HIGH), + SOFTWARE_NODE_REFERENCE(&pxa2xx_gpiochip_node, 114, GPIO_ACTIVE_HIGH), }; -static struct platform_device spitz_mkp_device = { +static const struct property_entry spitz_mkp_properties[] = { + PROPERTY_ENTRY_ARRAY_U32("linux,keymap", spitz_keymap), + PROPERTY_ENTRY_REF_ARRAY("row-gpios", spitz_mkp_row_gpios), + PROPERTY_ENTRY_REF_ARRAY("col-gpios", spitz_mkp_col_gpios), + PROPERTY_ENTRY_U32("col-scan-delay-us", 10), + PROPERTY_ENTRY_U32("debounce-delay-ms", 10), + PROPERTY_ENTRY_BOOL("wakeup-source"), + { } +}; + +static const struct platform_device_info spitz_mkp_info __initconst = { .name = "matrix-keypad", - .id = -1, - .dev = { - .platform_data = &spitz_mkp_pdata, - }, + .id = PLATFORM_DEVID_NONE, + .properties = spitz_mkp_properties, }; + static void __init spitz_mkp_init(void) { - platform_device_register(&spitz_mkp_device); + struct platform_device *pd; + int err; + + pd = platform_device_register_full(&spitz_mkp_info); + err = PTR_ERR_OR_ZERO(pd); + if (err) + pr_err("failed to create keypad device: %d\n", err); } #else static inline void spitz_mkp_init(void) {} From patchwork Mon Aug 5 01:47:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 13753071 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 smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 771DAC52D72 for ; Mon, 5 Aug 2024 01:47:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) id 65D71C4AF11; Mon, 5 Aug 2024 01:47:29 +0000 (UTC) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 4D0BBC32786 for ; Mon, 5 Aug 2024 01:47:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 smtp.kernel.org 4D0BBC32786 Authentication-Results: smtp.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fd6ed7688cso80404795ad.3 for ; Sun, 04 Aug 2024 18:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722822448; x=1723427248; darn=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=S8pmaXOrL2r8fZW3tjkXa1wARMkR0Ev0bNttjQMTW54=; b=Dgoj94SIw280fEroHhXcCsAHf3aphaj8m0z3g/Zm60AcOYKA1IpD8L2RjR6zl1NMkn RQc0FlIbf7DOvjzSx15KrwUVomiX05r31nNna9L8hvRKVPqNTvKCV017wWUPDqX3LOsr LSFeH0PJlJKfpdeUs9hBf5Jj8q4JhlvbBOQA0NcB11EdNsNgi+MVFQEN0a5ixQiLyie7 UQs51pxDfpWfvGcdgfXhhdmWwkrr97aRA+wFu9SplptPHy88kwznAJY3YBdleQxJxebS 0x+yY8GZS0MdILPZDgBnI8b1HUN4tNoPZfeZgrQXRgv0S3ssL4gZuUqVO+tYL+LzrAco Wdtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722822448; x=1723427248; 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=S8pmaXOrL2r8fZW3tjkXa1wARMkR0Ev0bNttjQMTW54=; b=vvhrK/AgAcUpFGFKNks/aeeHTklZTxWn1pIhe68PmrsgZwiX8DvvxVVPqRemYf0ySa o0i+oFEJEG7ydhyvHw9U2tYsGzaHnVQUn+t733OeyTEZit1qWRae9CDIpAZoL/5fgA9H IOgvtZ32FKfpWSZQiVGb+EY3sMN6bUewySKNtuNXHXzWAki1yAjC1GY3YH4VeaWFCP+B uaPR1vU0DljvIAQpNw/TfG2UrWvtCVynRLYgEVR+HaTpzBiGjFHlwtlj9NsbOfYVcad1 IOE8ywdLHpMUHm1pNlLR3ulM/eTXeqGDgvt9USQNTOIYDHQNaLxa49cJY09aaASWuQxS dlSA== X-Forwarded-Encrypted: i=1; AJvYcCXDZRKhj5GynuvajsmMAmtCyy/xpE27fQUV2D11D4Ca9npBvEHF9UqitX2ymDQ3lkP5gAVzTOaCMwPLC/dJIw== X-Gm-Message-State: AOJu0Yz2ViRkFrJ/96qkpQfA69VwEoex8kWOBnuEPo2J2K3X7Dj3y2tP l/7B5+0cPH2x3ISNy8GNBHqluEZmepJS+rTTXlKowu50PfgEDfat X-Google-Smtp-Source: AGHT+IELHyzgpC2WLKDDZzgQ7L0kQLg3FlBo97+NT6C6YgjQSp7KnuWLpBuWntbjhEBRfo3w6b4qdA== X-Received: by 2002:a17:902:e885:b0:1fb:1500:17e0 with SMTP id d9443c01a7336-1ff572ba31bmr83762825ad.28.1722822447500; Sun, 04 Aug 2024 18:47:27 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2620:15c:9d:2:22e4:17a:28a:7497]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59295790sm55836015ad.261.2024.08.04.18.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 18:47:27 -0700 (PDT) From: Dmitry Torokhov List-Id: To: Haojian Zhuang , Daniel Mack , Robert Jarzmik , Arnd Bergmann , Linus Walleij , soc@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH 5/5] Input: matrix_keypad - remove support for platform data Date: Sun, 4 Aug 2024 18:47:08 -0700 Message-ID: <20240805014710.1961677-6-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog In-Reply-To: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> References: <20240805014710.1961677-1-dmitry.torokhov@gmail.com> MIME-Version: 1.0 There are no more users of struct matrix_keypad_platform_data in the kernel, remove support for it from the driver. Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/matrix_keypad.c | 74 ++------------------------ include/linux/input/matrix_keypad.h | 48 ----------------- 2 files changed, 3 insertions(+), 119 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 5f7e6f27e9c5..3c38bae576ed 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -271,55 +271,6 @@ static int matrix_keypad_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(matrix_keypad_pm_ops, matrix_keypad_suspend, matrix_keypad_resume); -static int matrix_keypad_init_pdata_gpio(struct platform_device *pdev, - const struct matrix_keypad_platform_data *pdata, - struct matrix_keypad *keypad) -{ - int i, err; - - keypad->num_col_gpios = pdata->num_col_gpios; - keypad->num_row_gpios = pdata->num_row_gpios; - - /* initialized strobe lines as outputs, activated */ - for (i = 0; i < pdata->num_col_gpios; i++) { - 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); - return err; - } - - keypad->col_gpios[i] = gpio_to_desc(pdata->col_gpios[i]); - - if (pdata->active_low ^ gpiod_is_active_low(keypad->col_gpios[i])) - gpiod_toggle_active_low(keypad->col_gpios[i]); - - gpiod_direction_output(keypad->col_gpios[i], 1); - } - - for (i = 0; i < pdata->num_row_gpios; i++) { - 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); - return err; - } - - keypad->row_gpios[i] = gpio_to_desc(pdata->row_gpios[i]); - - if (pdata->active_low ^ gpiod_is_active_low(keypad->row_gpios[i])) - gpiod_toggle_active_low(keypad->row_gpios[i]); - - gpiod_direction_input(keypad->row_gpios[i]); - } - - return 0; -} - static int matrix_keypad_init_gpio(struct platform_device *pdev, struct matrix_keypad *keypad) { @@ -420,11 +371,8 @@ static int matrix_keypad_setup_interrupts(struct platform_device *pdev, static int matrix_keypad_probe(struct platform_device *pdev) { - const struct matrix_keypad_platform_data *pdata = - dev_get_platdata(&pdev->dev); struct matrix_keypad *keypad; struct input_dev *input_dev; - bool autorepeat; bool wakeup; int err; @@ -448,16 +396,7 @@ static int matrix_keypad_probe(struct platform_device *pdev) device_property_read_u32(&pdev->dev, "col-scan-delay-us", &keypad->col_scan_delay_us); - if (pdata) { - keypad->col_scan_delay_us = pdata->col_scan_delay_us; - keypad->debounce_ms = pdata->debounce_ms; - keypad->drive_inactive_cols = pdata->drive_inactive_cols; - } - - if (pdata) - err = matrix_keypad_init_pdata_gpio(pdev, pdata, keypad); - else - err = matrix_keypad_init_gpio(pdev, keypad); + err = matrix_keypad_init_gpio(pdev, keypad); if (err) return err; @@ -472,8 +411,7 @@ static int matrix_keypad_probe(struct platform_device *pdev) input_dev->open = matrix_keypad_start; input_dev->close = matrix_keypad_stop; - err = matrix_keypad_build_keymap(pdata ? pdata->keymap_data : NULL, - NULL, + err = matrix_keypad_build_keymap(NULL, NULL, keypad->num_row_gpios, keypad->num_col_gpios, NULL, input_dev); @@ -482,11 +420,7 @@ static int matrix_keypad_probe(struct platform_device *pdev) return -ENOMEM; } - autorepeat = !device_property_read_bool(&pdev->dev, - "linux,no-autorepeat"); - if (autorepeat && pdata->no_autorepeat) - autorepeat = false; - if (autorepeat) + if (!device_property_read_bool(&pdev->dev, "linux,no-autorepeat")) __set_bit(EV_REP, input_dev->evbit); input_set_capability(input_dev, EV_MSC, MSC_SCAN); @@ -499,8 +433,6 @@ static int matrix_keypad_probe(struct platform_device *pdev) wakeup = device_property_read_bool(&pdev->dev, "wakeup-source") || /* legacy */ device_property_read_bool(&pdev->dev, "linux,wakeup"); - if (!wakeup && pdata) - wakeup = pdata->wakeup; device_init_wakeup(&pdev->dev, wakeup); platform_set_drvdata(pdev, keypad); diff --git a/include/linux/input/matrix_keypad.h b/include/linux/input/matrix_keypad.h index b8d8d69eba29..90867f44ab4d 100644 --- a/include/linux/input/matrix_keypad.h +++ b/include/linux/input/matrix_keypad.h @@ -34,52 +34,6 @@ struct matrix_keymap_data { unsigned int keymap_size; }; -/** - * struct matrix_keypad_platform_data - platform-dependent keypad data - * @keymap_data: pointer to &matrix_keymap_data - * @row_gpios: pointer to array of gpio numbers representing rows - * @col_gpios: pointer to array of gpio numbers reporesenting colums - * @num_row_gpios: actual number of row gpios used by device - * @num_col_gpios: actual number of col gpios used by device - * @col_scan_delay_us: delay, measured in microseconds, that is - * needed before we can keypad after activating column gpio - * @debounce_ms: debounce interval in milliseconds - * @clustered_irq: may be specified if interrupts of all row/column GPIOs - * are bundled to one single irq - * @clustered_irq_flags: flags that are needed for the clustered irq - * @active_low: gpio polarity - * @wakeup: controls whether the device should be set up as wakeup - * source - * @no_autorepeat: disable key autorepeat - * @drive_inactive_cols: drive inactive columns during scan, rather than - * making them inputs. - * - * This structure represents platform-specific data that use used by - * matrix_keypad driver to perform proper initialization. - */ -struct matrix_keypad_platform_data { - const struct matrix_keymap_data *keymap_data; - - const unsigned int *row_gpios; - const unsigned int *col_gpios; - - unsigned int num_row_gpios; - unsigned int num_col_gpios; - - unsigned int col_scan_delay_us; - - /* key debounce interval in milli-second */ - unsigned int debounce_ms; - - unsigned int clustered_irq; - unsigned int clustered_irq_flags; - - bool active_low; - bool wakeup; - bool no_autorepeat; - bool drive_inactive_cols; -}; - int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, const char *keymap_name, unsigned int rows, unsigned int cols, @@ -88,6 +42,4 @@ int matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data, int matrix_keypad_parse_properties(struct device *dev, unsigned int *rows, unsigned int *cols); -#define matrix_keypad_parse_of_params matrix_keypad_parse_properties - #endif /* _MATRIX_KEYPAD_H */