* [PATCH] pinctrl: lpc18xx: create pin cap lookup helper
@ 2015-05-06 17:11 ` Joachim Eastwood
0 siblings, 0 replies; 4+ messages in thread
From: Joachim Eastwood @ 2015-05-06 17:11 UTC (permalink / raw)
To: linus.walleij; +Cc: linux-gpio, linux-arm-kernel, Joachim Eastwood
Both pconf_get_pin and pconf_set_pin needs to lookup pin cap based
on the pin number. Create a common helper function that both
functions can use that also handles the case where no pin number is
found in the pins array.
This also fixes a small bug in pconf_get_pin where pconf_get_i2c0
would use the pins array index rather than the pin number.
Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
Hi Linus,
Patch is based on your linux-pinctrl devel branch.
Since it's a new driver feel free to squash it with the initial commit.
regards,
Joachim Eastwood
drivers/pinctrl/pinctrl-lpc18xx.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c
index 15fe1e2535c2..0facb7e64fef 100644
--- a/drivers/pinctrl/pinctrl-lpc18xx.c
+++ b/drivers/pinctrl/pinctrl-lpc18xx.c
@@ -729,6 +729,18 @@ static int lpc18xx_pconf_get_pin(enum pin_config_param param, int *arg, u32 reg,
return 0;
}
+static struct lpc18xx_pin_caps *lpc18xx_get_pin_caps(unsigned pin)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
+ if (lpc18xx_pins[i].number == pin)
+ return lpc18xx_pins[i].drv_data;
+ }
+
+ return NULL;
+}
+
static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin,
unsigned long *config)
{
@@ -737,14 +749,11 @@ static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin,
struct lpc18xx_pin_caps *pin_cap;
int ret, arg = 0;
u32 reg;
- int i;
- for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
- if (lpc18xx_pins[i].number == pin)
- pin = i;
- }
+ pin_cap = lpc18xx_get_pin_caps(pin);
+ if (!pin_cap)
+ return -EINVAL;
- pin_cap = lpc18xx_pins[pin].drv_data;
reg = readl(scu->base + pin_cap->offset);
if (pin_cap->type == TYPE_I2C0)
@@ -905,12 +914,10 @@ static int lpc18xx_pconf_set(struct pinctrl_dev *pctldev, unsigned pin,
int ret;
int i;
- for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
- if (lpc18xx_pins[i].number == pin)
- break;
- }
+ pin_cap = lpc18xx_get_pin_caps(pin);
+ if (!pin_cap)
+ return -EINVAL;
- pin_cap = lpc18xx_pins[i].drv_data;
reg = readl(scu->base + pin_cap->offset);
for (i = 0; i < num_configs; i++) {
--
1.8.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] pinctrl: lpc18xx: create pin cap lookup helper
@ 2015-05-06 17:11 ` Joachim Eastwood
0 siblings, 0 replies; 4+ messages in thread
From: Joachim Eastwood @ 2015-05-06 17:11 UTC (permalink / raw)
To: linux-arm-kernel
Both pconf_get_pin and pconf_set_pin needs to lookup pin cap based
on the pin number. Create a common helper function that both
functions can use that also handles the case where no pin number is
found in the pins array.
This also fixes a small bug in pconf_get_pin where pconf_get_i2c0
would use the pins array index rather than the pin number.
Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
Hi Linus,
Patch is based on your linux-pinctrl devel branch.
Since it's a new driver feel free to squash it with the initial commit.
regards,
Joachim Eastwood
drivers/pinctrl/pinctrl-lpc18xx.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c
index 15fe1e2535c2..0facb7e64fef 100644
--- a/drivers/pinctrl/pinctrl-lpc18xx.c
+++ b/drivers/pinctrl/pinctrl-lpc18xx.c
@@ -729,6 +729,18 @@ static int lpc18xx_pconf_get_pin(enum pin_config_param param, int *arg, u32 reg,
return 0;
}
+static struct lpc18xx_pin_caps *lpc18xx_get_pin_caps(unsigned pin)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
+ if (lpc18xx_pins[i].number == pin)
+ return lpc18xx_pins[i].drv_data;
+ }
+
+ return NULL;
+}
+
static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin,
unsigned long *config)
{
@@ -737,14 +749,11 @@ static int lpc18xx_pconf_get(struct pinctrl_dev *pctldev, unsigned pin,
struct lpc18xx_pin_caps *pin_cap;
int ret, arg = 0;
u32 reg;
- int i;
- for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
- if (lpc18xx_pins[i].number == pin)
- pin = i;
- }
+ pin_cap = lpc18xx_get_pin_caps(pin);
+ if (!pin_cap)
+ return -EINVAL;
- pin_cap = lpc18xx_pins[pin].drv_data;
reg = readl(scu->base + pin_cap->offset);
if (pin_cap->type == TYPE_I2C0)
@@ -905,12 +914,10 @@ static int lpc18xx_pconf_set(struct pinctrl_dev *pctldev, unsigned pin,
int ret;
int i;
- for (i = 0; i < ARRAY_SIZE(lpc18xx_pins); i++) {
- if (lpc18xx_pins[i].number == pin)
- break;
- }
+ pin_cap = lpc18xx_get_pin_caps(pin);
+ if (!pin_cap)
+ return -EINVAL;
- pin_cap = lpc18xx_pins[i].drv_data;
reg = readl(scu->base + pin_cap->offset);
for (i = 0; i < num_configs; i++) {
--
1.8.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] pinctrl: lpc18xx: create pin cap lookup helper
2015-05-06 17:11 ` Joachim Eastwood
@ 2015-05-12 11:18 ` Linus Walleij
-1 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2015-05-12 11:18 UTC (permalink / raw)
To: Joachim Eastwood; +Cc: linux-gpio, linux-arm-kernel
On Wed, May 6, 2015 at 7:11 PM, Joachim Eastwood <manabian@gmail.com> wrote:
> Both pconf_get_pin and pconf_set_pin needs to lookup pin cap based
> on the pin number. Create a common helper function that both
> functions can use that also handles the case where no pin number is
> found in the pins array.
>
> This also fixes a small bug in pconf_get_pin where pconf_get_i2c0
> would use the pins array index rather than the pin number.
>
> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> ---
> Hi Linus,
>
> Patch is based on your linux-pinctrl devel branch.
> Since it's a new driver feel free to squash it with the initial commit.
Patch applied, removed the other hackish check.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] pinctrl: lpc18xx: create pin cap lookup helper
@ 2015-05-12 11:18 ` Linus Walleij
0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2015-05-12 11:18 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, May 6, 2015 at 7:11 PM, Joachim Eastwood <manabian@gmail.com> wrote:
> Both pconf_get_pin and pconf_set_pin needs to lookup pin cap based
> on the pin number. Create a common helper function that both
> functions can use that also handles the case where no pin number is
> found in the pins array.
>
> This also fixes a small bug in pconf_get_pin where pconf_get_i2c0
> would use the pins array index rather than the pin number.
>
> Signed-off-by: Joachim Eastwood <manabian@gmail.com>
> ---
> Hi Linus,
>
> Patch is based on your linux-pinctrl devel branch.
> Since it's a new driver feel free to squash it with the initial commit.
Patch applied, removed the other hackish check.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-05-12 11:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-06 17:11 [PATCH] pinctrl: lpc18xx: create pin cap lookup helper Joachim Eastwood
2015-05-06 17:11 ` Joachim Eastwood
2015-05-12 11:18 ` Linus Walleij
2015-05-12 11:18 ` Linus Walleij
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.