Commit ceef91dc authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Simon Horman

sh-pfc: Skip gpiochip registration when no GPIO resource is found

Boards/platforms that register dedicated GPIO devices will not supply a
memory resource for GPIOs. Try to locate the GPIO memory resource at
initialization time, and skip registration of the gpiochip if the
resource can't be found.

This is a temporary modification to ease the transition to separate GPIO
drivers. It should be reverted when all boards and platforms will have
been moved.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarSimon Horman <horms+renesas@verge.net.au>
parent 1a4fd58f
...@@ -101,24 +101,9 @@ static void gpio_setup_data_reg(struct sh_pfc_chip *chip, unsigned gpio) ...@@ -101,24 +101,9 @@ static void gpio_setup_data_reg(struct sh_pfc_chip *chip, unsigned gpio)
static int gpio_setup_data_regs(struct sh_pfc_chip *chip) static int gpio_setup_data_regs(struct sh_pfc_chip *chip)
{ {
struct sh_pfc *pfc = chip->pfc; struct sh_pfc *pfc = chip->pfc;
unsigned long addr = pfc->info->data_regs[0].reg;
const struct pinmux_data_reg *dreg; const struct pinmux_data_reg *dreg;
unsigned int i; unsigned int i;
/* Find the window that contain the GPIO registers. */
for (i = 0; i < pfc->num_windows; ++i) {
struct sh_pfc_window *window = &pfc->window[i];
if (addr >= window->phys && addr < window->phys + window->size)
break;
}
if (i == pfc->num_windows)
return -EINVAL;
/* GPIO data registers must be in the first memory resource. */
chip->mem = &pfc->window[i];
/* Count the number of data registers, allocate memory and initialize /* Count the number of data registers, allocate memory and initialize
* them. * them.
*/ */
...@@ -319,7 +304,8 @@ static int gpio_function_setup(struct sh_pfc_chip *chip) ...@@ -319,7 +304,8 @@ static int gpio_function_setup(struct sh_pfc_chip *chip)
*/ */
static struct sh_pfc_chip * static struct sh_pfc_chip *
sh_pfc_add_gpiochip(struct sh_pfc *pfc, int(*setup)(struct sh_pfc_chip *)) sh_pfc_add_gpiochip(struct sh_pfc *pfc, int(*setup)(struct sh_pfc_chip *),
struct sh_pfc_window *mem)
{ {
struct sh_pfc_chip *chip; struct sh_pfc_chip *chip;
int ret; int ret;
...@@ -328,6 +314,7 @@ sh_pfc_add_gpiochip(struct sh_pfc *pfc, int(*setup)(struct sh_pfc_chip *)) ...@@ -328,6 +314,7 @@ sh_pfc_add_gpiochip(struct sh_pfc *pfc, int(*setup)(struct sh_pfc_chip *))
if (unlikely(!chip)) if (unlikely(!chip))
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
chip->mem = mem;
chip->pfc = pfc; chip->pfc = pfc;
ret = setup(chip); ret = setup(chip);
...@@ -357,8 +344,24 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) ...@@ -357,8 +344,24 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
if (pfc->info->data_regs == NULL) if (pfc->info->data_regs == NULL)
return 0; return 0;
/* Find the memory window that contain the GPIO registers. Boards that
* register a separate GPIO device will not supply a memory resource
* that covers the data registers. In that case don't try to handle
* GPIOs.
*/
for (i = 0; i < pfc->num_windows; ++i) {
struct sh_pfc_window *window = &pfc->window[i];
if (pfc->info->data_regs[0].reg >= window->phys &&
pfc->info->data_regs[0].reg < window->phys + window->size)
break;
}
if (i == pfc->num_windows)
return 0;
/* Register the real GPIOs chip. */ /* Register the real GPIOs chip. */
chip = sh_pfc_add_gpiochip(pfc, gpio_pin_setup); chip = sh_pfc_add_gpiochip(pfc, gpio_pin_setup, &pfc->window[i]);
if (IS_ERR(chip)) if (IS_ERR(chip))
return PTR_ERR(chip); return PTR_ERR(chip);
...@@ -390,7 +393,7 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc) ...@@ -390,7 +393,7 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
if (pfc->info->nr_func_gpios == 0) if (pfc->info->nr_func_gpios == 0)
return 0; return 0;
chip = sh_pfc_add_gpiochip(pfc, gpio_function_setup); chip = sh_pfc_add_gpiochip(pfc, gpio_function_setup, NULL);
if (IS_ERR(chip)) if (IS_ERR(chip))
return PTR_ERR(chip); return PTR_ERR(chip);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment