Commit 20ec3e39 authored by Linus Walleij's avatar Linus Walleij

gpio: move the pin ranges into gpio_device

Instead of keeping this reference to the pin ranges in the
client driver-supplied gpio_chip, move it to the internal
gpio_device as the drivers have no need to inspect this.
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 4e6fd26d
...@@ -71,29 +71,29 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data) ...@@ -71,29 +71,29 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
* controller uses pin controller and the mapping is not contiguous the * controller uses pin controller and the mapping is not contiguous the
* offset might be different. * offset might be different.
*/ */
static int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, int pin) static int acpi_gpiochip_pin_to_gpio_offset(struct gpio_device *gdev, int pin)
{ {
struct gpio_pin_range *pin_range; struct gpio_pin_range *pin_range;
/* If there are no ranges in this chip, use 1:1 mapping */ /* If there are no ranges in this chip, use 1:1 mapping */
if (list_empty(&chip->pin_ranges)) if (list_empty(&gdev->pin_ranges))
return pin; return pin;
list_for_each_entry(pin_range, &chip->pin_ranges, node) { list_for_each_entry(pin_range, &gdev->pin_ranges, node) {
const struct pinctrl_gpio_range *range = &pin_range->range; const struct pinctrl_gpio_range *range = &pin_range->range;
int i; int i;
if (range->pins) { if (range->pins) {
for (i = 0; i < range->npins; i++) { for (i = 0; i < range->npins; i++) {
if (range->pins[i] == pin) if (range->pins[i] == pin)
return range->base + i - chip->base; return range->base + i - gdev->base;
} }
} else { } else {
if (pin >= range->pin_base && if (pin >= range->pin_base &&
pin < range->pin_base + range->npins) { pin < range->pin_base + range->npins) {
unsigned gpio_base; unsigned gpio_base;
gpio_base = range->base - chip->base; gpio_base = range->base - gdev->base;
return gpio_base + pin - range->pin_base; return gpio_base + pin - range->pin_base;
} }
} }
...@@ -102,7 +102,7 @@ static int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, int pin) ...@@ -102,7 +102,7 @@ static int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, int pin)
return -EINVAL; return -EINVAL;
} }
#else #else
static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_device *gdev,
int pin) int pin)
{ {
return pin; return pin;
...@@ -134,7 +134,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin) ...@@ -134,7 +134,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
if (!chip) if (!chip)
return ERR_PTR(-EPROBE_DEFER); return ERR_PTR(-EPROBE_DEFER);
offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin); offset = acpi_gpiochip_pin_to_gpio_offset(chip->gpiodev, pin);
if (offset < 0) if (offset < 0)
return ERR_PTR(offset); return ERR_PTR(offset);
...@@ -202,7 +202,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares, ...@@ -202,7 +202,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
if (!handler) if (!handler)
return AE_BAD_PARAMETER; return AE_BAD_PARAMETER;
pin = acpi_gpiochip_pin_to_gpio_offset(chip, pin); pin = acpi_gpiochip_pin_to_gpio_offset(chip->gpiodev, pin);
if (pin < 0) if (pin < 0)
return AE_BAD_PARAMETER; return AE_BAD_PARAMETER;
...@@ -673,7 +673,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address, ...@@ -673,7 +673,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
struct gpio_desc *desc; struct gpio_desc *desc;
bool found; bool found;
pin = acpi_gpiochip_pin_to_gpio_offset(chip, pin); pin = acpi_gpiochip_pin_to_gpio_offset(chip->gpiodev, pin);
if (pin < 0) { if (pin < 0) {
status = AE_BAD_PARAMETER; status = AE_BAD_PARAMETER;
goto out; goto out;
......
...@@ -532,8 +532,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data) ...@@ -532,8 +532,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
spin_unlock_irqrestore(&gpio_lock, flags); spin_unlock_irqrestore(&gpio_lock, flags);
#ifdef CONFIG_PINCTRL #ifdef CONFIG_PINCTRL
/* FIXME: move pin ranges to gpio_device */ INIT_LIST_HEAD(&gdev->pin_ranges);
INIT_LIST_HEAD(&chip->pin_ranges);
#endif #endif
status = gpiochip_set_desc_names(chip); status = gpiochip_set_desc_names(chip);
...@@ -1036,7 +1035,7 @@ int gpiochip_add_pingroup_range(struct gpio_chip *chip, ...@@ -1036,7 +1035,7 @@ int gpiochip_add_pingroup_range(struct gpio_chip *chip,
gpio_offset, gpio_offset + pin_range->range.npins - 1, gpio_offset, gpio_offset + pin_range->range.npins - 1,
pinctrl_dev_get_devname(pctldev), pin_group); pinctrl_dev_get_devname(pctldev), pin_group);
list_add_tail(&pin_range->node, &chip->pin_ranges); list_add_tail(&pin_range->node, &gdev->pin_ranges);
return 0; return 0;
} }
...@@ -1085,7 +1084,7 @@ int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name, ...@@ -1085,7 +1084,7 @@ int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
pinctl_name, pinctl_name,
pin_offset, pin_offset + npins - 1); pin_offset, pin_offset + npins - 1);
list_add_tail(&pin_range->node, &chip->pin_ranges); list_add_tail(&pin_range->node, &gdev->pin_ranges);
return 0; return 0;
} }
...@@ -1098,8 +1097,9 @@ EXPORT_SYMBOL_GPL(gpiochip_add_pin_range); ...@@ -1098,8 +1097,9 @@ EXPORT_SYMBOL_GPL(gpiochip_add_pin_range);
void gpiochip_remove_pin_ranges(struct gpio_chip *chip) void gpiochip_remove_pin_ranges(struct gpio_chip *chip)
{ {
struct gpio_pin_range *pin_range, *tmp; struct gpio_pin_range *pin_range, *tmp;
struct gpio_device *gdev = chip->gpiodev;
list_for_each_entry_safe(pin_range, tmp, &chip->pin_ranges, node) { list_for_each_entry_safe(pin_range, tmp, &gdev->pin_ranges, node) {
list_del(&pin_range->node); list_del(&pin_range->node);
pinctrl_remove_gpio_range(pin_range->pctldev, pinctrl_remove_gpio_range(pin_range->pctldev,
&pin_range->range); &pin_range->range);
......
...@@ -55,6 +55,16 @@ struct gpio_device { ...@@ -55,6 +55,16 @@ struct gpio_device {
int base; int base;
u16 ngpio; u16 ngpio;
struct list_head list; struct list_head list;
#ifdef CONFIG_PINCTRL
/*
* If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
* describe the actual pin range which they serve in an SoC. This
* information would be used by pinctrl subsystem to configure
* corresponding pins for gpio usage.
*/
struct list_head pin_ranges;
#endif
}; };
/** /**
......
...@@ -181,15 +181,6 @@ struct gpio_chip { ...@@ -181,15 +181,6 @@ struct gpio_chip {
int (*of_xlate)(struct gpio_chip *gc, int (*of_xlate)(struct gpio_chip *gc,
const struct of_phandle_args *gpiospec, u32 *flags); const struct of_phandle_args *gpiospec, u32 *flags);
#endif #endif
#ifdef CONFIG_PINCTRL
/*
* If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
* describe the actual pin range which they serve in an SoC. This
* information would be used by pinctrl subsystem to configure
* corresponding pins for gpio usage.
*/
struct list_head pin_ranges;
#endif
}; };
extern const char *gpiochip_is_requested(struct gpio_chip *chip, extern const char *gpiochip_is_requested(struct gpio_chip *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