Skip to content

Commit

Permalink
ramips: pinctrl-aw9523: update to current upstream
Browse files Browse the repository at this point in the history
Various cleanups and bugfixes were applied.

Signed-off-by: Rosen Penev <[email protected]>
Link: openwrt/openwrt#16215
Signed-off-by: Robert Marko <[email protected]>
  • Loading branch information
neheb authored and robimarko committed Sep 7, 2024
1 parent 39d0fd6 commit 8e6543f
Show file tree
Hide file tree
Showing 14 changed files with 1,744 additions and 1,200 deletions.
1,128 changes: 0 additions & 1,128 deletions target/linux/ramips/files/drivers/pinctrl/pinctrl-aw9523.c

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 52279c3d50d964c646692c42a0db87ef7bb451cc Mon Sep 17 00:00:00 2001
From: Linus Walleij <[email protected]>
Date: Wed, 6 Mar 2024 08:54:25 +0100
Subject: [PATCH] pinctrl: aw9523: Add proper terminator

The of_device_id array needs to be terminated with a NULL
entry.

Reported-by: kernel test robot <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Signed-off-by: Linus Walleij <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
drivers/pinctrl/pinctrl-aw9523.c | 1 +
1 file changed, 1 insertion(+)

--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -1099,6 +1099,7 @@ MODULE_DEVICE_TABLE(i2c, aw9523_i2c_id_t

static const struct of_device_id of_aw9523_i2c_match[] = {
{ .compatible = "awinic,aw9523-pinctrl", },
+ { }
};
MODULE_DEVICE_TABLE(of, of_aw9523_i2c_match);

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From e5e8a58023707472e5dbe9bc7b473a8703b401e0 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Fri, 29 Mar 2024 12:55:15 +0200
Subject: [PATCH] pinctrl: aw9523: Destroy mutex on ->remove()

If aw9523_hw_init() fails on ->remove() the mutex left alive.
Destroy it in that case as well. While at it, remove never
true check at the beginning of the function.

Signed-off-by: Andy Shevchenko <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
drivers/pinctrl/pinctrl-aw9523.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -1067,10 +1067,6 @@ err_disable_vregs:
static void aw9523_remove(struct i2c_client *client)
{
struct aw9523 *awi = i2c_get_clientdata(client);
- int ret;
-
- if (!awi)
- return;

/*
* If the chip VIO is connected to a regulator that we can turn
@@ -1082,10 +1078,8 @@ static void aw9523_remove(struct i2c_cli
regulator_disable(awi->vio_vreg);
} else {
mutex_lock(&awi->i2c_lock);
- ret = aw9523_hw_init(awi);
+ aw9523_hw_init(awi);
mutex_unlock(&awi->i2c_lock);
- if (ret)
- return;
}

mutex_destroy(&awi->i2c_lock);
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
From f91eafcb18e096108cd19d24ab71a0db5bc12416 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Fri, 29 Mar 2024 12:55:16 +0200
Subject: [PATCH] pinctrl: aw9523: Use correct error code for not supported
functionality

The pin control subsystem internally uses ENOTSUPP for the not supported
functionality. The checkpatch is false positive about this error code.

Signed-off-by: Andy Shevchenko <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
drivers/pinctrl/pinctrl-aw9523.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -6,6 +6,7 @@
*/

#include <linux/bitfield.h>
+#include <linux/errno.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/i2c.h>
@@ -239,7 +240,7 @@ static int aw9523_pcfg_param_to_reg(enum
reg = AW9523_REG_OUT_STATE(pin);
break;
default:
- return -EOPNOTSUPP;
+ return -ENOTSUPP;
}
*r = reg;

@@ -290,7 +291,7 @@ static int aw9523_pconf_get(struct pinct
val = FIELD_GET(AW9523_GCR_GPOMD_MASK, val);
break;
default:
- return -EOPNOTSUPP;
+ return -ENOTSUPP;
}
if (val < 1)
return -EINVAL;
@@ -344,7 +345,7 @@ static int aw9523_pconf_set(struct pinct
case PIN_CONFIG_DRIVE_OPEN_DRAIN:
/* Open-Drain is supported only on port 0 */
if (pin >= AW9523_PINS_PER_PORT) {
- rc = -EOPNOTSUPP;
+ rc = -ENOTSUPP;
goto end;
}
mask = AW9523_GCR_GPOMD_MASK;
@@ -361,7 +362,7 @@ static int aw9523_pconf_set(struct pinct
val = AW9523_GCR_GPOMD_MASK;
break;
default:
- rc = -EOPNOTSUPP;
+ rc = -ENOTSUPP;
goto end;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
From 091655b9285d837db520381924c689bd5dc5d286 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Fri, 29 Mar 2024 12:55:17 +0200
Subject: [PATCH] pinctrl: aw9523: Always try both ports in
aw9523_gpio_set_multiple()

The ports are equivalent from the user's point of view. Don't limit
trying them both if writing to one fails.

Signed-off-by: Andy Shevchenko <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
drivers/pinctrl/pinctrl-aw9523.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -653,7 +653,7 @@ static void aw9523_gpio_set_multiple(str
struct aw9523 *awi = gpiochip_get_data(chip);
u8 mask_lo, mask_hi, bits_lo, bits_hi;
unsigned int reg;
- int ret = 0;
+ int ret;

mask_lo = *mask & U8_MAX;
mask_hi = (*mask >> 8) & U8_MAX;
@@ -663,10 +663,8 @@ static void aw9523_gpio_set_multiple(str
bits_hi = (*bits >> 8) & U8_MAX;

ret = regmap_write_bits(awi->regmap, reg, mask_hi, bits_hi);
- if (ret) {
+ if (ret)
dev_warn(awi->dev, "Cannot write port1 out level\n");
- goto out;
- }
}
if (mask_lo) {
reg = AW9523_REG_OUT_STATE(0);
@@ -675,7 +673,6 @@ static void aw9523_gpio_set_multiple(str
if (ret)
dev_warn(awi->dev, "Cannot write port0 out level\n");
}
-out:
mutex_unlock(&awi->i2c_lock);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
From 418ee9488ff74ab4ada3a539a2840dda9e56f847 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Fri, 29 Mar 2024 12:55:18 +0200
Subject: [PATCH] pinctrl: aw9523: Make use of struct pinfunction and
PINCTRL_PINFUNCTION()

Since pin control provides a generic data type and a macro for
the pin function definition, use them in the driver.

Signed-off-by: Andy Shevchenko <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
drivers/pinctrl/pinctrl-aw9523.c | 32 ++++++--------------------------
1 file changed, 6 insertions(+), 26 deletions(-)

--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -67,18 +67,6 @@ struct aw9523_irq {
};

/*
- * struct aw9523_pinmux - Pin mux params
- * @name: Name of the mux
- * @grps: Groups of the mux
- * @num_grps: Number of groups (sizeof array grps)
- */
-struct aw9523_pinmux {
- const char *name;
- const char * const *grps;
- const u8 num_grps;
-};
-
-/*
* struct aw9523 - Main driver structure
* @dev: device handle
* @regmap: regmap handle for current device
@@ -158,17 +146,9 @@ static const char * const gpio_pwm_group
};

/* Warning: Do NOT reorder this array */
-static const struct aw9523_pinmux aw9523_pmx[] = {
- {
- .name = "pwm",
- .grps = gpio_pwm_groups,
- .num_grps = ARRAY_SIZE(gpio_pwm_groups),
- },
- {
- .name = "gpio",
- .grps = gpio_pwm_groups,
- .num_grps = ARRAY_SIZE(gpio_pwm_groups),
- },
+static const struct pinfunction aw9523_pmx[] = {
+ PINCTRL_PINFUNCTION("pwm", gpio_pwm_groups, ARRAY_SIZE(gpio_pwm_groups)),
+ PINCTRL_PINFUNCTION("gpio", gpio_pwm_groups, ARRAY_SIZE(gpio_pwm_groups)),
};

static int aw9523_pmx_get_funcs_count(struct pinctrl_dev *pctl)
@@ -184,10 +164,10 @@ static const char *aw9523_pmx_get_fname(

static int aw9523_pmx_get_groups(struct pinctrl_dev *pctl, unsigned int sel,
const char * const **groups,
- unsigned int * const num_groups)
+ unsigned int * const ngroups)
{
- *groups = aw9523_pmx[sel].grps;
- *num_groups = aw9523_pmx[sel].num_grps;
+ *groups = aw9523_pmx[sel].groups;
+ *ngroups = aw9523_pmx[sel].ngroups;
return 0;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 66413f0468d35adb352c76bc286bf6f6746ba354 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Fri, 29 Mar 2024 12:55:19 +0200
Subject: [PATCH] pinctrl: aw9523: Use temporary variable for HW IRQ number

There are two different ways on how to get HW IRQ number in some functions.
Unify that by using temporary variable and irqd_to_hwirq() call.

Signed-off-by: Andy Shevchenko <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
drivers/pinctrl/pinctrl-aw9523.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -428,12 +428,12 @@ static int aw9523_gpio_irq_type(struct i
static void aw9523_irq_mask(struct irq_data *d)
{
struct aw9523 *awi = gpiochip_get_data(irq_data_get_irq_chip_data(d));
- unsigned int n = d->hwirq % AW9523_PINS_PER_PORT;
+ irq_hw_number_t hwirq = irqd_to_hwirq(d);
+ unsigned int n = hwirq % AW9523_PINS_PER_PORT;

- regmap_update_bits(awi->regmap,
- AW9523_REG_INTR_DIS(d->hwirq),
+ regmap_update_bits(awi->regmap, AW9523_REG_INTR_DIS(hwirq),
BIT(n), BIT(n));
- gpiochip_disable_irq(&awi->gpio, irqd_to_hwirq(d));
+ gpiochip_disable_irq(&awi->gpio, hwirq);
}

/*
@@ -446,11 +446,11 @@ static void aw9523_irq_mask(struct irq_d
static void aw9523_irq_unmask(struct irq_data *d)
{
struct aw9523 *awi = gpiochip_get_data(irq_data_get_irq_chip_data(d));
- unsigned int n = d->hwirq % AW9523_PINS_PER_PORT;
+ irq_hw_number_t hwirq = irqd_to_hwirq(d);
+ unsigned int n = hwirq % AW9523_PINS_PER_PORT;

- gpiochip_enable_irq(&awi->gpio, irqd_to_hwirq(d));
- regmap_update_bits(awi->regmap,
- AW9523_REG_INTR_DIS(d->hwirq),
+ gpiochip_enable_irq(&awi->gpio, hwirq);
+ regmap_update_bits(awi->regmap, AW9523_REG_INTR_DIS(hwirq),
BIT(n), 0);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 4210ef801a248223a0ea5f47b5446081b4925e10 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Fri, 29 Mar 2024 12:55:20 +0200
Subject: [PATCH] pinctrl: aw9523: Get rid of redundant ' & U8_MAX' pieces

When the variable is declared as u8, no need to perform ' & U8_MAX'
as it's implied anyway.

Signed-off-by: Andy Shevchenko <[email protected]>
Message-ID: <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
drivers/pinctrl/pinctrl-aw9523.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -603,7 +603,7 @@ static int aw9523_gpio_get_multiple(stru
mutex_lock(&awi->i2c_lock);

/* Port 0 (gpio 0-7) */
- m = *mask & U8_MAX;
+ m = *mask;
if (m) {
ret = _aw9523_gpio_get_multiple(awi, 0, &state, m);
if (ret)
@@ -612,7 +612,7 @@ static int aw9523_gpio_get_multiple(stru
*bits = state;

/* Port 1 (gpio 8-15) */
- m = (*mask >> 8) & U8_MAX;
+ m = *mask >> 8;
if (m) {
ret = _aw9523_gpio_get_multiple(awi, AW9523_PINS_PER_PORT,
&state, m);
@@ -635,20 +635,20 @@ static void aw9523_gpio_set_multiple(str
unsigned int reg;
int ret;

- mask_lo = *mask & U8_MAX;
- mask_hi = (*mask >> 8) & U8_MAX;
+ mask_lo = *mask;
+ mask_hi = *mask >> 8;
+ bits_lo = *bits;
+ bits_hi = *bits >> 8;
+
mutex_lock(&awi->i2c_lock);
if (mask_hi) {
reg = AW9523_REG_OUT_STATE(AW9523_PINS_PER_PORT);
- bits_hi = (*bits >> 8) & U8_MAX;
-
ret = regmap_write_bits(awi->regmap, reg, mask_hi, bits_hi);
if (ret)
dev_warn(awi->dev, "Cannot write port1 out level\n");
}
if (mask_lo) {
reg = AW9523_REG_OUT_STATE(0);
- bits_lo = *bits & U8_MAX;
ret = regmap_write_bits(awi->regmap, reg, mask_lo, bits_lo);
if (ret)
dev_warn(awi->dev, "Cannot write port0 out level\n");
Loading

0 comments on commit 8e6543f

Please sign in to comment.