From patchwork Sun Nov 10 20:59:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 842399 Received: from fgw23-7.mail.saunalahti.fi (fgw23-7.mail.saunalahti.fi [62.142.5.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D9F1157487 for ; Sun, 10 Nov 2024 21:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731272463; cv=none; b=bDh5RILm2zuOioNvn/SUZ9UEYPB6xbkpEB/nTjaNT7hNwwPMf3zo5/xJM78yq9vdfhTiBEkGj4UtWZ0PaHLckUo2PZLQ/n38hbrm46IFQoTnKBsMKRcjNiiQIxxxgTzLl+IZSdbQ7Neq32IBxS1UXBtKOSw4KqS2+oevzZKYaZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731272463; c=relaxed/simple; bh=QZQswWBjiA6sKRY7WdJThEE2ZM5Xh2HKQzfY+W6JxpI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g/yTbTlfAnfJMxsyAWu3Jw4PvfF/jqBKeW/9U4HDrKU+QCs+gPa2Fgi4tC4hPqwcm7LSW9V8HkF92bNF17n+MOQmz4jGvxoDOwflxucQs8aZiyO1HQ0kMdbPi91iurcEEJFMIP5wy/uZMxI9F5NJ/zEPntyTbVvzluIWsnAu+UA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com Received: from localhost (88-113-24-75.elisa-laajakaista.fi [88.113.24.75]) by fgw20.mail.saunalahti.fi (Halon) with ESMTP id dd80ce7b-9fa6-11ef-9b01-005056bd6ce9; Sun, 10 Nov 2024 23:00:50 +0200 (EET) From: Andy Shevchenko To: Patrick Rudolph , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Andy Shevchenko Subject: [PATCH v1 3/6] pinctrl: cy8c95x0: use flexible sleeping in reset function Date: Sun, 10 Nov 2024 22:59:43 +0200 Message-ID: <20241110210040.18918-4-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241110210040.18918-1-andy.shevchenko@gmail.com> References: <20241110210040.18918-1-andy.shevchenko@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The device reset assert and deassert length was created by usleep_range() but that does not ensure optimal handling of all the different values from device tree properties. By switching to the new flexible sleeping helper function, fsleep(), the correct delay function is called depending on delay length, e.g. udelay(), usleep_range() or msleep(). While at it, move out GPIO consumer name setting of the reset conditional, the all necessary checks are already done there, so logically that call is not related to the reset sequence. Signed-off-by: Andy Shevchenko --- drivers/pinctrl/pinctrl-cy8c95x0.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c index cb6d9458c1e8..54b080f63226 100644 --- a/drivers/pinctrl/pinctrl-cy8c95x0.c +++ b/drivers/pinctrl/pinctrl-cy8c95x0.c @@ -1475,12 +1475,11 @@ static int cy8c95x0_probe(struct i2c_client *client) chip->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(chip->gpio_reset)) return dev_err_probe(chip->dev, PTR_ERR(chip->gpio_reset), "Failed to get GPIO 'reset'\n"); + gpiod_set_consumer_name(chip->gpio_reset, "CY8C95X0 RESET"); if (chip->gpio_reset) { - usleep_range(1000, 2000); + fsleep(1000); gpiod_set_value_cansleep(chip->gpio_reset, 0); - usleep_range(250000, 300000); - - gpiod_set_consumer_name(chip->gpio_reset, "CY8C95X0 RESET"); + fsleep(250000); } /* Regmap for direct and paged registers */ From patchwork Sun Nov 10 20:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 842400 Received: from fgw22-7.mail.saunalahti.fi (fgw22-7.mail.saunalahti.fi [62.142.5.83]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 881BC15747A for ; Sun, 10 Nov 2024 21:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.83 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731272460; cv=none; b=naw2CeieXzOuUQFzL9ULoikFbwQUAHgJ2YMw8UzDCUQogl78+xhXKbrUNE1yShx6OO4l9OycTweQFERai9+fZZqpxioMEx4Kss6bGcuK+6MoBVvWYUZtWTnlCrdvUW4sOWCQTyu+PsrttqP0kokKhwxrGDz/KX35QLHHwh3HkjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731272460; c=relaxed/simple; bh=StWURDzPXrrNwdPZqNvuhg+95fYmCc2elITSw30Am9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SkIGoD3thDDvZeh6nDrMQyHzzvXd9K4yGKnIl0zhH/ew/92rj8iNAaP6MGgj7ryQTN1g4t9JKgUzOnzyEdTltGsw3+IXKQh6I6ypVvIStbWm8OZbhV8UMpnaoQ66WnVQPbYP3xxyKa2qT3TaLJXMniZ9eFkgpD5ZiLuo25a0b0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com Received: from localhost (88-113-24-75.elisa-laajakaista.fi [88.113.24.75]) by fgw22.mail.saunalahti.fi (Halon) with ESMTP id de7c4074-9fa6-11ef-8261-005056bdf889; Sun, 10 Nov 2024 23:00:51 +0200 (EET) From: Andy Shevchenko To: Patrick Rudolph , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Andy Shevchenko Subject: [PATCH v1 4/6] pinctrl: cy8c95x0: Use temporary variable for struct device Date: Sun, 10 Nov 2024 22:59:44 +0200 Message-ID: <20241110210040.18918-5-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241110210040.18918-1-andy.shevchenko@gmail.com> References: <20241110210040.18918-1-andy.shevchenko@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use a temporary variable for the struct device pointers to avoid dereferencing. This makes code a bit neater. Signed-off-by: Andy Shevchenko --- drivers/pinctrl/pinctrl-cy8c95x0.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c index 54b080f63226..8b118fd09e9e 100644 --- a/drivers/pinctrl/pinctrl-cy8c95x0.c +++ b/drivers/pinctrl/pinctrl-cy8c95x0.c @@ -1429,16 +1429,17 @@ static int cy8c95x0_detect(struct i2c_client *client, static int cy8c95x0_probe(struct i2c_client *client) { + struct device *dev = &client->dev; struct cy8c95x0_pinctrl *chip; struct regmap_config regmap_conf; struct regmap_range_cfg regmap_range_conf; int ret; - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); if (!chip) return -ENOMEM; - chip->dev = &client->dev; + chip->dev = dev; /* Set the device type */ chip->driver_data = (uintptr_t)i2c_get_match_data(client); @@ -1467,14 +1468,14 @@ static int cy8c95x0_probe(struct i2c_client *client) return -ENODEV; } - ret = devm_regulator_get_enable(&client->dev, "vdd"); + ret = devm_regulator_get_enable(dev, "vdd"); if (ret) - return dev_err_probe(&client->dev, ret, "failed to enable regulator vdd\n"); + return dev_err_probe(dev, ret, "failed to enable regulator vdd\n"); /* bring the chip out of reset if reset pin is provided */ - chip->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); + chip->gpio_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(chip->gpio_reset)) - return dev_err_probe(chip->dev, PTR_ERR(chip->gpio_reset), "Failed to get GPIO 'reset'\n"); + return dev_err_probe(dev, PTR_ERR(chip->gpio_reset), "Failed to get GPIO 'reset'\n"); gpiod_set_consumer_name(chip->gpio_reset, "CY8C95X0 RESET"); if (chip->gpio_reset) { fsleep(1000); From patchwork Sun Nov 10 20:59:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 842398 Received: from fgw21-7.mail.saunalahti.fi (fgw21-7.mail.saunalahti.fi [62.142.5.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 811BF1531C0 for ; Sun, 10 Nov 2024 21:01:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.142.5.82 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731272468; cv=none; b=XB1CgHmFRUV7DOM9zDLTS0eZSI8ZXBk2t5nmZMctertFYtUd2XykKvKhi0f2KKBUZLme97EVGYnF2fx+EHHNinMpvuhPUC2lBfz7wcuSeX44rKPx8Z/tbR9O6uFW3MPeIJF4+6nNA3FgFLs+ASBsch2vuKIOMxhpKkm1YdDSFbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731272468; c=relaxed/simple; bh=I1PF87o/v3duEmVol3hK5Hn3dWDF6plXuD4SahJVq1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fDHUe3rkI6z63U+ZItf0sKTN8AmASrN3LFSP0VEutx9kQPIcKCYN1pclF3IXGfNJyTUu/GohthZTSKsAGaY1ve0sCWt5m1edf07kVQf20x+BRc92wuuslrVR/EodvwJ9kzm1C3B+qUmB+l2xsk1+K3GfQpIJ+bTnejoHsYI3jM0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com; spf=fail smtp.mailfrom=gmail.com; arc=none smtp.client-ip=62.142.5.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=gmail.com Received: from localhost (88-113-24-75.elisa-laajakaista.fi [88.113.24.75]) by fgw21.mail.saunalahti.fi (Halon) with ESMTP id df906ca3-9fa6-11ef-8874-005056bdd08f; Sun, 10 Nov 2024 23:00:53 +0200 (EET) From: Andy Shevchenko To: Patrick Rudolph , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij , Andy Shevchenko Subject: [PATCH v1 5/6] pinctrl: cy8c95x0: embed iterator to the for-loop Date: Sun, 10 Nov 2024 22:59:45 +0200 Message-ID: <20241110210040.18918-6-andy.shevchenko@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241110210040.18918-1-andy.shevchenko@gmail.com> References: <20241110210040.18918-1-andy.shevchenko@gmail.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When we iterate through nports the iterator variable is effectively being not used outside of the loop. Make it clear by moving its definition into the for-loop. This makes code cleaner as well. Signed-off-by: Andy Shevchenko --- drivers/pinctrl/pinctrl-cy8c95x0.c | 36 +++++++++++++----------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/drivers/pinctrl/pinctrl-cy8c95x0.c b/drivers/pinctrl/pinctrl-cy8c95x0.c index 8b118fd09e9e..8c611abd4745 100644 --- a/drivers/pinctrl/pinctrl-cy8c95x0.c +++ b/drivers/pinctrl/pinctrl-cy8c95x0.c @@ -159,7 +159,7 @@ struct cy8c95x0_pinctrl { DECLARE_BITMAP(irq_trig_high, MAX_LINE); DECLARE_BITMAP(push_pull, MAX_LINE); DECLARE_BITMAP(shiftmask, MAX_LINE); - int nport; + unsigned int nport; struct gpio_chip gpio_chip; unsigned long driver_data; struct device *dev; @@ -610,9 +610,8 @@ static int cy8c95x0_write_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, DECLARE_BITMAP(tmask, MAX_LINE); DECLARE_BITMAP(tval, MAX_LINE); int write_val; - int ret = 0; - int i; u8 bits; + int ret; /* Add the 4 bit gap of Gport2 */ bitmap_andnot(tmask, mask, chip->shiftmask, MAX_LINE); @@ -623,7 +622,7 @@ static int cy8c95x0_write_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, bitmap_shift_left(tval, tval, 4, MAX_LINE); bitmap_replace(tval, tval, val, chip->shiftmask, BANK_SZ * 3); - for (i = 0; i < chip->nport; i++) { + for (unsigned int i = 0; i < chip->nport; i++) { /* Skip over unused banks */ bits = bitmap_get_value8(tmask, i * BANK_SZ); if (!bits) @@ -632,15 +631,13 @@ static int cy8c95x0_write_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, write_val = bitmap_get_value8(tval, i * BANK_SZ); ret = cy8c95x0_regmap_update_bits(chip, reg, i, bits, write_val); - if (ret < 0) - goto out; + if (ret < 0) { + dev_err(chip->dev, "failed writing register %d, port %u: err %d\n", reg, i, ret); + return ret; + } } -out: - if (ret < 0) - dev_err(chip->dev, "failed writing register %d, port %d: err %d\n", reg, i, ret); - - return ret; + return 0; } static int cy8c95x0_read_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, @@ -650,9 +647,8 @@ static int cy8c95x0_read_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, DECLARE_BITMAP(tval, MAX_LINE); DECLARE_BITMAP(tmp, MAX_LINE); int read_val; - int ret = 0; - int i; u8 bits; + int ret; /* Add the 4 bit gap of Gport2 */ bitmap_andnot(tmask, mask, chip->shiftmask, MAX_LINE); @@ -663,15 +659,17 @@ static int cy8c95x0_read_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, bitmap_shift_left(tval, tval, 4, MAX_LINE); bitmap_replace(tval, tval, val, chip->shiftmask, BANK_SZ * 3); - for (i = 0; i < chip->nport; i++) { + for (unsigned int i = 0; i < chip->nport; i++) { /* Skip over unused banks */ bits = bitmap_get_value8(tmask, i * BANK_SZ); if (!bits) continue; ret = cy8c95x0_regmap_read(chip, reg, i, &read_val); - if (ret < 0) - goto out; + if (ret < 0) { + dev_err(chip->dev, "failed reading register %d, port %u: err %d\n", reg, i, ret); + return ret; + } read_val &= bits; read_val |= bitmap_get_value8(tval, i * BANK_SZ) & ~bits; @@ -682,11 +680,7 @@ static int cy8c95x0_read_regs_mask(struct cy8c95x0_pinctrl *chip, int reg, bitmap_shift_right(tmp, tval, 4, MAX_LINE); bitmap_replace(val, tmp, tval, chip->shiftmask, MAX_LINE); -out: - if (ret < 0) - dev_err(chip->dev, "failed reading register %d, port %d: err %d\n", reg, i, ret); - - return ret; + return 0; } static int cy8c95x0_gpio_direction_input(struct gpio_chip *gc, unsigned int off)