pinctrl: nomadik: find chip from local array
Instead of indexing around the GPIO ranges to find a chip, look directly in the local array of state containers for nmk_gpio_chip:s. Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
This commit is contained in:
parent
bc222ef4f7
commit
6ca7d2e352
@ -1354,35 +1354,40 @@ static int nmk_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct pinctrl_gpio_range *
|
static struct nmk_gpio_chip *find_nmk_gpio_from_pin(unsigned pin)
|
||||||
nmk_match_gpio_range(struct pinctrl_dev *pctldev, unsigned offset)
|
|
||||||
{
|
{
|
||||||
struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
|
|
||||||
int i;
|
int i;
|
||||||
|
struct nmk_gpio_chip *nmk_gpio;
|
||||||
|
|
||||||
for (i = 0; i < npct->soc->gpio_num_ranges; i++) {
|
for(i = 0; i < NMK_MAX_BANKS; i++) {
|
||||||
struct pinctrl_gpio_range *range;
|
nmk_gpio = nmk_gpio_chips[i];
|
||||||
|
if (!nmk_gpio)
|
||||||
range = &npct->soc->gpio_ranges[i];
|
continue;
|
||||||
if (offset >= range->pin_base &&
|
if (pin >= nmk_gpio->chip.base &&
|
||||||
offset <= (range->pin_base + range->npins - 1))
|
pin < nmk_gpio->chip.base + nmk_gpio->chip.ngpio)
|
||||||
return range;
|
return nmk_gpio;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct gpio_chip *find_gc_from_pin(unsigned pin)
|
||||||
|
{
|
||||||
|
struct nmk_gpio_chip *nmk_gpio = find_nmk_gpio_from_pin(pin);
|
||||||
|
|
||||||
|
if (nmk_gpio)
|
||||||
|
return &nmk_gpio->chip;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void nmk_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
|
static void nmk_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
|
||||||
unsigned offset)
|
unsigned offset)
|
||||||
{
|
{
|
||||||
struct pinctrl_gpio_range *range;
|
struct gpio_chip *chip = find_gc_from_pin(offset);
|
||||||
struct gpio_chip *chip;
|
|
||||||
|
|
||||||
range = nmk_match_gpio_range(pctldev, offset);
|
if (!chip) {
|
||||||
if (!range || !range->gc) {
|
|
||||||
seq_printf(s, "invalid pin offset");
|
seq_printf(s, "invalid pin offset");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
chip = range->gc;
|
|
||||||
nmk_gpio_dbg_show_one(s, pctldev, chip, offset - chip->base, offset);
|
nmk_gpio_dbg_show_one(s, pctldev, chip, offset - chip->base, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1727,25 +1732,16 @@ static int nmk_pmx_set(struct pinctrl_dev *pctldev, unsigned function,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < g->npins; i++) {
|
for (i = 0; i < g->npins; i++) {
|
||||||
struct pinctrl_gpio_range *range;
|
|
||||||
struct nmk_gpio_chip *nmk_chip;
|
struct nmk_gpio_chip *nmk_chip;
|
||||||
struct gpio_chip *chip;
|
|
||||||
unsigned bit;
|
unsigned bit;
|
||||||
|
|
||||||
range = nmk_match_gpio_range(pctldev, g->pins[i]);
|
nmk_chip = find_nmk_gpio_from_pin(g->pins[i]);
|
||||||
if (!range) {
|
if (!nmk_chip) {
|
||||||
dev_err(npct->dev,
|
dev_err(npct->dev,
|
||||||
"invalid pin offset %d in group %s at index %d\n",
|
"invalid pin offset %d in group %s at index %d\n",
|
||||||
g->pins[i], g->name, i);
|
g->pins[i], g->name, i);
|
||||||
goto out_glitch;
|
goto out_glitch;
|
||||||
}
|
}
|
||||||
if (!range->gc) {
|
|
||||||
dev_err(npct->dev, "GPIO chip missing in range for pin offset %d in group %s at index %d\n",
|
|
||||||
g->pins[i], g->name, i);
|
|
||||||
goto out_glitch;
|
|
||||||
}
|
|
||||||
chip = range->gc;
|
|
||||||
nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
|
|
||||||
dev_dbg(npct->dev, "setting pin %d to altsetting %d\n", g->pins[i], g->altsetting);
|
dev_dbg(npct->dev, "setting pin %d to altsetting %d\n", g->pins[i], g->altsetting);
|
||||||
|
|
||||||
clk_enable(nmk_chip->clk);
|
clk_enable(nmk_chip->clk);
|
||||||
@ -1861,25 +1857,17 @@ static int nmk_pin_config_set(struct pinctrl_dev *pctldev, unsigned pin,
|
|||||||
};
|
};
|
||||||
struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
|
struct nmk_pinctrl *npct = pinctrl_dev_get_drvdata(pctldev);
|
||||||
struct nmk_gpio_chip *nmk_chip;
|
struct nmk_gpio_chip *nmk_chip;
|
||||||
struct pinctrl_gpio_range *range;
|
|
||||||
struct gpio_chip *chip;
|
|
||||||
unsigned bit;
|
unsigned bit;
|
||||||
pin_cfg_t cfg;
|
pin_cfg_t cfg;
|
||||||
int pull, slpm, output, val, i;
|
int pull, slpm, output, val, i;
|
||||||
bool lowemi, gpiomode, sleep;
|
bool lowemi, gpiomode, sleep;
|
||||||
|
|
||||||
range = nmk_match_gpio_range(pctldev, pin);
|
nmk_chip = find_nmk_gpio_from_pin(pin);
|
||||||
if (!range) {
|
if (!nmk_chip) {
|
||||||
dev_err(npct->dev, "invalid pin offset %d\n", pin);
|
dev_err(npct->dev,
|
||||||
|
"invalid pin offset %d\n", pin);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (!range->gc) {
|
|
||||||
dev_err(npct->dev, "GPIO chip missing in range for pin %d\n",
|
|
||||||
pin);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
chip = range->gc;
|
|
||||||
nmk_chip = container_of(chip, struct nmk_gpio_chip, chip);
|
|
||||||
|
|
||||||
for (i = 0; i < num_configs; i++) {
|
for (i = 0; i < num_configs; i++) {
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user