Skip to content

Commit 16ba046

Browse files
dtorBartosz Golaszewski
authored andcommitted
gpiolib: acpi: teach acpi_find_gpio() to handle data-only nodes
In preparation of switching all ACPI-based GPIO lookups to go through acpi_find_gpio() we need to make sure it can handle data-only ACPI nodes, same as existing acpi_node_get_gpiod(). 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 2b6bce8 commit 16ba046

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

drivers/gpio/gpiolib-acpi.c

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,9 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
864864
* function only returns the first.
865865
*/
866866
static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
867-
const char *propname, int index,
868-
struct acpi_gpio_info *info)
867+
const char *propname,
868+
int index,
869+
struct acpi_gpio_info *info)
869870
{
870871
struct acpi_gpio_lookup lookup;
871872
int ret;
@@ -896,6 +897,44 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
896897
return ret ? ERR_PTR(ret) : lookup.desc;
897898
}
898899

900+
/**
901+
* acpi_get_gpiod_from_data() - get a GPIO descriptor from ACPI data node
902+
* @fwnode: pointer to an ACPI firmware node to get the GPIO information from
903+
* @propname: Property name of the GPIO
904+
* @index: index of GpioIo/GpioInt resource (starting from %0)
905+
* @info: info pointer to fill in (optional)
906+
*
907+
* This function uses the property-based GPIO lookup to get to the GPIO
908+
* resource with the relevant information from a data-only ACPI firmware node
909+
* and uses that to obtain the GPIO descriptor to return.
910+
*
911+
* If the GPIO cannot be translated or there is an error an ERR_PTR is
912+
* returned.
913+
*/
914+
static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
915+
const char *propname,
916+
int index,
917+
struct acpi_gpio_info *info)
918+
{
919+
struct acpi_gpio_lookup lookup;
920+
int ret;
921+
922+
if (!is_acpi_data_node(fwnode))
923+
return ERR_PTR(-ENODEV);
924+
925+
if (!propname)
926+
return ERR_PTR(-EINVAL);
927+
928+
lookup.index = index;
929+
930+
ret = acpi_gpio_property_lookup(fwnode, propname, index, &lookup);
931+
if (ret)
932+
return ERR_PTR(ret);
933+
934+
ret = acpi_gpio_resource_lookup(&lookup, info);
935+
return ret ? ERR_PTR(ret) : lookup.desc;
936+
}
937+
899938
static bool acpi_can_fallback_to_crs(struct acpi_device *adev,
900939
const char *con_id)
901940
{
@@ -912,16 +951,12 @@ struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
912951
enum gpiod_flags *dflags,
913952
unsigned long *lookupflags)
914953
{
915-
struct acpi_device *adev;
954+
struct acpi_device *adev = to_acpi_device_node(fwnode);
916955
struct acpi_gpio_info info;
917956
struct gpio_desc *desc;
918957
char propname[32];
919958
int i;
920959

921-
adev = to_acpi_device_node(fwnode);
922-
if (!adev)
923-
return ERR_PTR(-ENODEV);
924-
925960
/* Try first from _DSD */
926961
for (i = 0; i < ARRAY_SIZE(gpio_suffixes); i++) {
927962
if (con_id) {
@@ -932,7 +967,12 @@ struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
932967
gpio_suffixes[i]);
933968
}
934969

935-
desc = acpi_get_gpiod_by_index(adev, propname, idx, &info);
970+
if (adev)
971+
desc = acpi_get_gpiod_by_index(adev,
972+
propname, idx, &info);
973+
else
974+
desc = acpi_get_gpiod_from_data(fwnode,
975+
propname, idx, &info);
936976
if (!IS_ERR(desc))
937977
break;
938978
if (PTR_ERR(desc) == -EPROBE_DEFER)
@@ -941,7 +981,7 @@ struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,
941981

942982
/* Then from plain _CRS GPIOs */
943983
if (IS_ERR(desc)) {
944-
if (!acpi_can_fallback_to_crs(adev, con_id))
984+
if (!adev || !acpi_can_fallback_to_crs(adev, con_id))
945985
return ERR_PTR(-ENOENT);
946986

947987
desc = acpi_get_gpiod_by_index(adev, NULL, idx, &info);
@@ -979,29 +1019,13 @@ struct gpio_desc *acpi_node_get_gpiod(struct fwnode_handle *fwnode,
9791019
const char *propname, int index,
9801020
struct acpi_gpio_info *info)
9811021
{
982-
struct acpi_gpio_lookup lookup;
9831022
struct acpi_device *adev;
984-
int ret;
9851023

9861024
adev = to_acpi_device_node(fwnode);
9871025
if (adev)
9881026
return acpi_get_gpiod_by_index(adev, propname, index, info);
9891027

990-
if (!is_acpi_data_node(fwnode))
991-
return ERR_PTR(-ENODEV);
992-
993-
if (!propname)
994-
return ERR_PTR(-EINVAL);
995-
996-
memset(&lookup, 0, sizeof(lookup));
997-
lookup.index = index;
998-
999-
ret = acpi_gpio_property_lookup(fwnode, propname, index, &lookup);
1000-
if (ret)
1001-
return ERR_PTR(ret);
1002-
1003-
ret = acpi_gpio_resource_lookup(&lookup, info);
1004-
return ret ? ERR_PTR(ret) : lookup.desc;
1028+
return acpi_get_gpiod_from_data(fwnode, propname, index, info);
10051029
}
10061030

10071031
/**

0 commit comments

Comments
 (0)