Skip to content

Commit b7452d6

Browse files
dtorBartosz Golaszewski
authored andcommitted
gpiolib: acpi: avoid leaking ACPI details into upper gpiolib layers
There is no need for the generic parts of GPIOLIB to be aware of implementation details of ACPI-bases lookups. Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Linus Walleij <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 16ba046 commit b7452d6

File tree

3 files changed

+48
-57
lines changed

3 files changed

+48
-57
lines changed

drivers/gpio/gpiolib-acpi.c

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ struct acpi_gpio_chip {
8989
struct list_head deferred_req_irqs_list_entry;
9090
};
9191

92+
/**
93+
* struct acpi_gpio_info - ACPI GPIO specific information
94+
* @adev: reference to ACPI device which consumes GPIO resource
95+
* @flags: GPIO initialization flags
96+
* @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
97+
* @pin_config: pin bias as provided by ACPI
98+
* @polarity: interrupt polarity as provided by ACPI
99+
* @triggering: triggering type as provided by ACPI
100+
* @wake_capable: wake capability as provided by ACPI
101+
* @debounce: debounce timeout as provided by ACPI
102+
* @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
103+
*/
104+
struct acpi_gpio_info {
105+
struct acpi_device *adev;
106+
enum gpiod_flags flags;
107+
bool gpioint;
108+
int pin_config;
109+
int polarity;
110+
int triggering;
111+
bool wake_capable;
112+
unsigned int debounce;
113+
unsigned int quirks;
114+
};
115+
92116
/*
93117
* For GPIO chips which call acpi_gpiochip_request_interrupts() before late_init
94118
* (so builtin drivers) we register the ACPI GpioInt IRQ handlers from a
@@ -670,8 +694,8 @@ __acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, enum gpiod_flags update)
670694
return ret;
671695
}
672696

673-
int
674-
acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *info)
697+
static int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags,
698+
struct acpi_gpio_info *info)
675699
{
676700
struct device *dev = &info->adev->dev;
677701
enum gpiod_flags old = *flags;
@@ -690,8 +714,8 @@ acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *inf
690714
return ret;
691715
}
692716

693-
int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
694-
struct acpi_gpio_info *info)
717+
static int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
718+
struct acpi_gpio_info *info)
695719
{
696720
switch (info->pin_config) {
697721
case ACPI_PIN_CONFIG_PULLUP:
@@ -1005,7 +1029,8 @@ struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
10051029
* @fwnode: pointer to an ACPI firmware node to get the GPIO information from
10061030
* @propname: Property name of the GPIO
10071031
* @index: index of GpioIo/GpioInt resource (starting from %0)
1008-
* @info: info pointer to fill in (optional)
1032+
* @lflags: bitmask of gpio_lookup_flags GPIO_* values
1033+
* @dflags: gpiod initialization flags
10091034
*
10101035
* If @fwnode is an ACPI device object, call acpi_get_gpiod_by_index() for it.
10111036
* Otherwise (i.e. it is a data-only non-device object), use the property-based
@@ -1017,15 +1042,25 @@ struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
10171042
*/
10181043
struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
10191044
const char *propname, int index,
1020-
struct acpi_gpio_info *info)
1045+
unsigned long *lflags,
1046+
enum gpiod_flags *dflags)
10211047
{
1048+
struct acpi_gpio_info info;
10221049
struct acpi_device *adev;
1050+
struct gpio_desc *desc;
10231051

10241052
adev = to_acpi_device_node(fwnode);
10251053
if (adev)
1026-
return acpi_get_gpiod_by_index(adev, propname, index, info);
1054+
desc = acpi_get_gpiod_by_index(adev, propname, index, &info);
1055+
else
1056+
desc = acpi_get_gpiod_from_data(fwnode, propname, index, &info);
10271057

1028-
return acpi_get_gpiod_from_data(fwnode, propname, index, info);
1058+
if (!IS_ERR(desc)) {
1059+
acpi_gpio_update_gpiod_flags(dflags, &info);
1060+
acpi_gpio_update_gpiod_lookup_flags(lflags, &info);
1061+
}
1062+
1063+
return desc;
10291064
}
10301065

10311066
/**

drivers/gpio/gpiolib-acpi.h

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,6 @@
1010

1111
struct acpi_device;
1212

13-
/**
14-
* struct acpi_gpio_info - ACPI GPIO specific information
15-
* @adev: reference to ACPI device which consumes GPIO resource
16-
* @flags: GPIO initialization flags
17-
* @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
18-
* @pin_config: pin bias as provided by ACPI
19-
* @polarity: interrupt polarity as provided by ACPI
20-
* @triggering: triggering type as provided by ACPI
21-
* @wake_capable: wake capability as provided by ACPI
22-
* @debounce: debounce timeout as provided by ACPI
23-
* @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
24-
*/
25-
struct acpi_gpio_info {
26-
struct acpi_device *adev;
27-
enum gpiod_flags flags;
28-
bool gpioint;
29-
int pin_config;
30-
int polarity;
31-
int triggering;
32-
bool wake_capable;
33-
unsigned int debounce;
34-
unsigned int quirks;
35-
};
36-
3713
#ifdef CONFIG_ACPI
3814
void acpi_gpiochip_add(struct gpio_chip *chip);
3915
void acpi_gpiochip_remove(struct gpio_chip *chip);
@@ -43,19 +19,15 @@ void acpi_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev);
4319
void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
4420
void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
4521

46-
int acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags,
47-
struct acpi_gpio_info *info);
48-
int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
49-
struct acpi_gpio_info *info);
50-
5122
struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
5223
const char *con_id,
5324
unsigned int idx,
5425
enum gpiod_flags *dflags,
5526
unsigned long *lookupflags);
5627
struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
5728
const char *propname, int index,
58-
struct acpi_gpio_info *info);
29+
unsigned long *lflags,
30+
enum gpiod_flags *dflags);
5931

6032
int acpi_gpio_count(struct device *dev, const char *con_id);
6133
#else
@@ -70,18 +42,6 @@ acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
7042
static inline void
7143
acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
7244

73-
static inline int
74-
acpi_gpio_update_gpiod_flags(enum gpiod_flags *flags, struct acpi_gpio_info *info)
75-
{
76-
return 0;
77-
}
78-
static inline int
79-
acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
80-
struct acpi_gpio_info *info)
81-
{
82-
return 0;
83-
}
84-
8545
static inline struct gpio_desc *
8646
acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id,
8747
unsigned int idx, enum gpiod_flags *dflags,
@@ -91,7 +51,7 @@ acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id,
9151
}
9252
static inline struct gpio_desc *
9353
acpi_node_get_gpiod(struct fwnode_handle *fwnode, const char *propname,
94-
int index, struct acpi_gpio_info *info)
54+
int index, unsigned long *lflags, enum gpiod_flags *dflags)
9555
{
9656
return ERR_PTR(-ENXIO);
9757
}

drivers/gpio/gpiolib.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,14 +3890,10 @@ static struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
38903890
label);
38913891
return desc;
38923892
} else if (is_acpi_node(fwnode)) {
3893-
struct acpi_gpio_info info;
3894-
3895-
desc = acpi_node_get_gpiod(fwnode, propname, index, &info);
3893+
desc = acpi_node_get_gpiod(fwnode, propname, index,
3894+
&lflags, &dflags);
38963895
if (IS_ERR(desc))
38973896
return desc;
3898-
3899-
acpi_gpio_update_gpiod_flags(&dflags, &info);
3900-
acpi_gpio_update_gpiod_lookup_flags(&lflags, &info);
39013897
} else {
39023898
return ERR_PTR(-EINVAL);
39033899
}

0 commit comments

Comments
 (0)