Skip to content

Commit

Permalink
pinctrl: lpc18xx: create pin cap lookup helper
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
  • Loading branch information
manabian authored and linusw committed May 12, 2015
1 parent e8e36d2 commit 403fbde
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions drivers/pinctrl/pinctrl-lpc18xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit 403fbde

Please sign in to comment.