aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpio/gpiolib-acpi.c18
-rw-r--r--drivers/gpio/gpiolib.c10
-rw-r--r--drivers/gpio/gpiolib.h10
-rw-r--r--include/linux/gpio/driver.h9
4 files changed, 24 insertions, 23 deletions
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 540cbc88c7a2..682070d20f00 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -71,29 +71,29 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
71 * controller uses pin controller and the mapping is not contiguous the 71 * controller uses pin controller and the mapping is not contiguous the
72 * offset might be different. 72 * offset might be different.
73 */ 73 */
74static int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, int pin) 74static int acpi_gpiochip_pin_to_gpio_offset(struct gpio_device *gdev, int pin)
75{ 75{
76 struct gpio_pin_range *pin_range; 76 struct gpio_pin_range *pin_range;
77 77
78 /* If there are no ranges in this chip, use 1:1 mapping */ 78 /* If there are no ranges in this chip, use 1:1 mapping */
79 if (list_empty(&chip->pin_ranges)) 79 if (list_empty(&gdev->pin_ranges))
80 return pin; 80 return pin;
81 81
82 list_for_each_entry(pin_range, &chip->pin_ranges, node) { 82 list_for_each_entry(pin_range, &gdev->pin_ranges, node) {
83 const struct pinctrl_gpio_range *range = &pin_range->range; 83 const struct pinctrl_gpio_range *range = &pin_range->range;
84 int i; 84 int i;
85 85
86 if (range->pins) { 86 if (range->pins) {
87 for (i = 0; i < range->npins; i++) { 87 for (i = 0; i < range->npins; i++) {
88 if (range->pins[i] == pin) 88 if (range->pins[i] == pin)
89 return range->base + i - chip->base; 89 return range->base + i - gdev->base;
90 } 90 }
91 } else { 91 } else {
92 if (pin >= range->pin_base && 92 if (pin >= range->pin_base &&
93 pin < range->pin_base + range->npins) { 93 pin < range->pin_base + range->npins) {
94 unsigned gpio_base; 94 unsigned gpio_base;
95 95
96 gpio_base = range->base - chip->base; 96 gpio_base = range->base - gdev->base;
97 return gpio_base + pin - range->pin_base; 97 return gpio_base + pin - range->pin_base;
98 } 98 }
99 } 99 }
@@ -102,7 +102,7 @@ static int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, int pin)
102 return -EINVAL; 102 return -EINVAL;
103} 103}
104#else 104#else
105static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_chip *chip, 105static inline int acpi_gpiochip_pin_to_gpio_offset(struct gpio_device *gdev,
106 int pin) 106 int pin)
107{ 107{
108 return pin; 108 return pin;
@@ -134,7 +134,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
134 if (!chip) 134 if (!chip)
135 return ERR_PTR(-EPROBE_DEFER); 135 return ERR_PTR(-EPROBE_DEFER);
136 136
137 offset = acpi_gpiochip_pin_to_gpio_offset(chip, pin); 137 offset = acpi_gpiochip_pin_to_gpio_offset(chip->gpiodev, pin);
138 if (offset < 0) 138 if (offset < 0)
139 return ERR_PTR(offset); 139 return ERR_PTR(offset);
140 140
@@ -202,7 +202,7 @@ static acpi_status acpi_gpiochip_request_interrupt(struct acpi_resource *ares,
202 if (!handler) 202 if (!handler)
203 return AE_BAD_PARAMETER; 203 return AE_BAD_PARAMETER;
204 204
205 pin = acpi_gpiochip_pin_to_gpio_offset(chip, pin); 205 pin = acpi_gpiochip_pin_to_gpio_offset(chip->gpiodev, pin);
206 if (pin < 0) 206 if (pin < 0)
207 return AE_BAD_PARAMETER; 207 return AE_BAD_PARAMETER;
208 208
@@ -673,7 +673,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
673 struct gpio_desc *desc; 673 struct gpio_desc *desc;
674 bool found; 674 bool found;
675 675
676 pin = acpi_gpiochip_pin_to_gpio_offset(chip, pin); 676 pin = acpi_gpiochip_pin_to_gpio_offset(chip->gpiodev, pin);
677 if (pin < 0) { 677 if (pin < 0) {
678 status = AE_BAD_PARAMETER; 678 status = AE_BAD_PARAMETER;
679 goto out; 679 goto out;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 646dea4f96ff..28984bbc079c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -532,8 +532,7 @@ int gpiochip_add_data(struct gpio_chip *chip, void *data)
532 spin_unlock_irqrestore(&gpio_lock, flags); 532 spin_unlock_irqrestore(&gpio_lock, flags);
533 533
534#ifdef CONFIG_PINCTRL 534#ifdef CONFIG_PINCTRL
535 /* FIXME: move pin ranges to gpio_device */ 535 INIT_LIST_HEAD(&gdev->pin_ranges);
536 INIT_LIST_HEAD(&chip->pin_ranges);
537#endif 536#endif
538 537
539 status = gpiochip_set_desc_names(chip); 538 status = gpiochip_set_desc_names(chip);
@@ -1036,7 +1035,7 @@ int gpiochip_add_pingroup_range(struct gpio_chip *chip,
1036 gpio_offset, gpio_offset + pin_range->range.npins - 1, 1035 gpio_offset, gpio_offset + pin_range->range.npins - 1,
1037 pinctrl_dev_get_devname(pctldev), pin_group); 1036 pinctrl_dev_get_devname(pctldev), pin_group);
1038 1037
1039 list_add_tail(&pin_range->node, &chip->pin_ranges); 1038 list_add_tail(&pin_range->node, &gdev->pin_ranges);
1040 1039
1041 return 0; 1040 return 0;
1042} 1041}
@@ -1085,7 +1084,7 @@ int gpiochip_add_pin_range(struct gpio_chip *chip, const char *pinctl_name,
1085 pinctl_name, 1084 pinctl_name,
1086 pin_offset, pin_offset + npins - 1); 1085 pin_offset, pin_offset + npins - 1);
1087 1086
1088 list_add_tail(&pin_range->node, &chip->pin_ranges); 1087 list_add_tail(&pin_range->node, &gdev->pin_ranges);
1089 1088
1090 return 0; 1089 return 0;
1091} 1090}
@@ -1098,8 +1097,9 @@ EXPORT_SYMBOL_GPL(gpiochip_add_pin_range);
1098void gpiochip_remove_pin_ranges(struct gpio_chip *chip) 1097void gpiochip_remove_pin_ranges(struct gpio_chip *chip)
1099{ 1098{
1100 struct gpio_pin_range *pin_range, *tmp; 1099 struct gpio_pin_range *pin_range, *tmp;
1100 struct gpio_device *gdev = chip->gpiodev;
1101 1101
1102 list_for_each_entry_safe(pin_range, tmp, &chip->pin_ranges, node) { 1102 list_for_each_entry_safe(pin_range, tmp, &gdev->pin_ranges, node) {
1103 list_del(&pin_range->node); 1103 list_del(&pin_range->node);
1104 pinctrl_remove_gpio_range(pin_range->pctldev, 1104 pinctrl_remove_gpio_range(pin_range->pctldev,
1105 &pin_range->range); 1105 &pin_range->range);
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index d154984c71d9..5a36908fd39d 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -55,6 +55,16 @@ struct gpio_device {
55 int base; 55 int base;
56 u16 ngpio; 56 u16 ngpio;
57 struct list_head list; 57 struct list_head list;
58
59#ifdef CONFIG_PINCTRL
60 /*
61 * If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
62 * describe the actual pin range which they serve in an SoC. This
63 * information would be used by pinctrl subsystem to configure
64 * corresponding pins for gpio usage.
65 */
66 struct list_head pin_ranges;
67#endif
58}; 68};
59 69
60/** 70/**
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 41c6144c473b..e2a934ce3e64 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -181,15 +181,6 @@ struct gpio_chip {
181 int (*of_xlate)(struct gpio_chip *gc, 181 int (*of_xlate)(struct gpio_chip *gc,
182 const struct of_phandle_args *gpiospec, u32 *flags); 182 const struct of_phandle_args *gpiospec, u32 *flags);
183#endif 183#endif
184#ifdef CONFIG_PINCTRL
185 /*
186 * If CONFIG_PINCTRL is enabled, then gpio controllers can optionally
187 * describe the actual pin range which they serve in an SoC. This
188 * information would be used by pinctrl subsystem to configure
189 * corresponding pins for gpio usage.
190 */
191 struct list_head pin_ranges;
192#endif
193}; 184};
194 185
195extern const char *gpiochip_is_requested(struct gpio_chip *chip, 186extern const char *gpiochip_is_requested(struct gpio_chip *chip,