sh-pfc: Split pins and functions definition tables
[deliverable/linux.git] / drivers / pinctrl / sh-pfc / gpio.c
index a535075c8b69f0aee1380ebc4fca94810dae5a69..2a99bef281ad3be10f92e06fef3acd6ebdf760c4 100644 (file)
@@ -38,12 +38,48 @@ static struct sh_pfc *gpio_to_pfc(struct gpio_chip *gc)
 
 static int sh_gpio_request(struct gpio_chip *gc, unsigned offset)
 {
-       return pinctrl_request_gpio(offset);
+       struct sh_pfc *pfc = gpio_to_pfc(gc);
+       unsigned long flags;
+       int ret = -EINVAL;
+
+       if (offset < pfc->info->nr_pins)
+               return pinctrl_request_gpio(offset);
+
+       pr_notice_once("Use of GPIO API for function requests is deprecated, convert to pinctrl\n");
+
+       spin_lock_irqsave(&pfc->lock, flags);
+
+       if (!sh_pfc_gpio_is_function(pfc, offset))
+               goto done;
+
+       if (sh_pfc_config_gpio(pfc, offset, PINMUX_TYPE_FUNCTION,
+                              GPIO_CFG_DRYRUN))
+               goto done;
+
+       if (sh_pfc_config_gpio(pfc, offset, PINMUX_TYPE_FUNCTION,
+                              GPIO_CFG_REQ))
+               goto done;
+
+       ret = 0;
+
+done:
+       spin_unlock_irqrestore(&pfc->lock, flags);
+       return ret;
 }
 
 static void sh_gpio_free(struct gpio_chip *gc, unsigned offset)
 {
-       pinctrl_free_gpio(offset);
+       struct sh_pfc *pfc = gpio_to_pfc(gc);
+       unsigned long flags;
+
+       if (offset < pfc->info->nr_pins)
+               return pinctrl_free_gpio(offset);
+
+       spin_lock_irqsave(&pfc->lock, flags);
+
+       sh_pfc_config_gpio(pfc, offset, PINMUX_TYPE_FUNCTION, GPIO_CFG_FREE);
+
+       spin_unlock_irqrestore(&pfc->lock, flags);
 }
 
 static void sh_gpio_set_value(struct sh_pfc *pfc, unsigned gpio, int value)
@@ -70,12 +106,26 @@ static int sh_gpio_get_value(struct sh_pfc *pfc, unsigned gpio)
 
 static int sh_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
 {
+       struct sh_pfc *pfc = gpio_to_pfc(gc);
+
+       if (offset >= pfc->info->nr_pins) {
+               /* Function GPIOs can only be requested, never configured. */
+               return -EINVAL;
+       }
+
        return pinctrl_gpio_direction_input(offset);
 }
 
 static int sh_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
                                    int value)
 {
+       struct sh_pfc *pfc = gpio_to_pfc(gc);
+
+       if (offset >= pfc->info->nr_pins) {
+               /* Function GPIOs can only be requested, never configured. */
+               return -EINVAL;
+       }
+
        sh_gpio_set_value(gpio_to_pfc(gc), offset, value);
 
        return pinctrl_gpio_direction_output(offset);
@@ -130,12 +180,10 @@ static void sh_pfc_gpio_setup(struct sh_pfc_chip *chip)
        gc->set = sh_gpio_set;
        gc->to_irq = sh_gpio_to_irq;
 
-       WARN_ON(pfc->info->first_gpio != 0); /* needs testing */
-
        gc->label = pfc->info->name;
        gc->owner = THIS_MODULE;
-       gc->base = pfc->info->first_gpio;
-       gc->ngpio = (pfc->info->last_gpio - pfc->info->first_gpio) + 1;
+       gc->base = 0;
+       gc->ngpio = pfc->info->nr_pins + pfc->info->nr_func_gpios;
 }
 
 int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
@@ -157,9 +205,9 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
 
        pfc->gpio = chip;
 
-       pr_info("%s handling gpio %d -> %d\n",
-               pfc->info->name, pfc->info->first_gpio,
-               pfc->info->last_gpio);
+       pr_info("%s handling gpio 0 -> %u\n",
+               pfc->info->name,
+               pfc->info->nr_pins + pfc->info->nr_func_gpios - 1);
 
        return 0;
 }
This page took 0.026242 seconds and 5 git commands to generate.