/**
  * gpio_to_pin() - GPIO range GPIO number to pin number translation
  * @range: GPIO range used for the translation
- * @gpio: gpio pin to translate to a pin number
+ * @gc: GPIO chip structure from the GPIO subsystem
+ * @offset: hardware offset of the GPIO relative to the controller
  *
  * Finds the pin number for a given GPIO using the specified GPIO range
  * as a base for translation. The distinction between linear GPIO ranges
  * result of successful pinctrl_get_device_gpio_range calls)!
  */
 static inline int gpio_to_pin(struct pinctrl_gpio_range *range,
-                               unsigned int gpio)
+                             struct gpio_chip *gc, unsigned int offset)
 {
-       unsigned int offset = gpio - range->base;
+       unsigned int pin = gc->base + offset - range->base;
        if (range->pins)
-               return range->pins[offset];
+               return range->pins[pin];
        else
-               return range->pin_base + offset;
+               return range->pin_base + pin;
 }
 
 /**
        mutex_lock(&pctldev->mutex);
 
        /* Convert to the pin controllers number space */
-       pin = gpio_to_pin(range, gc->base + offset);
+       pin = gpio_to_pin(range, gc, offset);
 
        result = pinmux_can_be_used_for_gpio(pctldev, pin);
 
        mutex_lock(&pctldev->mutex);
 
        /* Convert to the pin controllers number space */
-       pin = gpio_to_pin(range, gc->base + offset);
+       pin = gpio_to_pin(range, gc, offset);
 
        ret = pinmux_request_gpio(pctldev, range, pin, gc->base + offset);
 
        mutex_lock(&pctldev->mutex);
 
        /* Convert to the pin controllers number space */
-       pin = gpio_to_pin(range, gc->base + offset);
+       pin = gpio_to_pin(range, gc, offset);
 
        pinmux_free_gpio(pctldev, pin, range);
 
        mutex_lock(&pctldev->mutex);
 
        /* Convert to the pin controllers number space */
-       pin = gpio_to_pin(range, gc->base + offset);
+       pin = gpio_to_pin(range, gc, offset);
        ret = pinmux_gpio_direction(pctldev, range, pin, input);
 
        mutex_unlock(&pctldev->mutex);
                return ret;
 
        mutex_lock(&pctldev->mutex);
-       pin = gpio_to_pin(range, gc->base + offset);
+       pin = gpio_to_pin(range, gc, offset);
        ret = pinconf_set_config(pctldev, pin, configs, ARRAY_SIZE(configs));
        mutex_unlock(&pctldev->mutex);