Commit d079524a authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

ACPI / gpio: Split acpi_get_gpiod_by_index()

Split acpi_get_gpiod_by_index() into three smaller routines to
allow the subsequent change of the generic firmware node properties
code to be more strarightforward.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 3a7a2ab8
...@@ -389,6 +389,8 @@ struct acpi_gpio_lookup { ...@@ -389,6 +389,8 @@ struct acpi_gpio_lookup {
struct acpi_gpio_info info; struct acpi_gpio_info info;
int index; int index;
int pin_index; int pin_index;
bool active_low;
struct acpi_device *adev;
struct gpio_desc *desc; struct gpio_desc *desc;
int n; int n;
}; };
...@@ -425,6 +427,59 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data) ...@@ -425,6 +427,59 @@ static int acpi_find_gpio(struct acpi_resource *ares, void *data)
return 1; return 1;
} }
static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
struct acpi_gpio_info *info)
{
struct list_head res_list;
int ret;
INIT_LIST_HEAD(&res_list);
ret = acpi_dev_get_resources(lookup->adev, &res_list, acpi_find_gpio,
lookup);
if (ret < 0)
return ret;
acpi_dev_free_resource_list(&res_list);
if (!lookup->desc)
return -ENOENT;
if (info) {
*info = lookup->info;
if (lookup->active_low)
info->active_low = lookup->active_low;
}
return 0;
}
static int acpi_gpio_property_lookup(struct acpi_device *adev,
const char *propname, int index,
struct acpi_gpio_lookup *lookup)
{
struct acpi_reference_args args;
int ret;
memset(&args, 0, sizeof(args));
ret = acpi_dev_get_property_reference(adev, propname, index, &args);
if (ret && !acpi_get_driver_gpio_data(adev, propname, index, &args))
return ret;
/*
* The property was found and resolved, so need to lookup the GPIO based
* on returned args.
*/
lookup->adev = args.adev;
if (args.nargs >= 2) {
lookup->index = args.args[0];
lookup->pin_index = args.args[1];
/* 3rd argument, if present is used to specify active_low. */
if (args.nargs >= 3)
lookup->active_low = !!args.args[2];
}
return 0;
}
/** /**
* acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources * acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources
* @adev: pointer to a ACPI device to get GPIO from * @adev: pointer to a ACPI device to get GPIO from
...@@ -452,8 +507,6 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev, ...@@ -452,8 +507,6 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
struct acpi_gpio_info *info) struct acpi_gpio_info *info)
{ {
struct acpi_gpio_lookup lookup; struct acpi_gpio_lookup lookup;
struct list_head resource_list;
bool active_low = false;
int ret; int ret;
if (!adev) if (!adev)
...@@ -463,58 +516,22 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev, ...@@ -463,58 +516,22 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
lookup.index = index; lookup.index = index;
if (propname) { if (propname) {
struct acpi_reference_args args;
dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname); dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
memset(&args, 0, sizeof(args)); ret = acpi_gpio_property_lookup(adev, propname, index, &lookup);
ret = acpi_dev_get_property_reference(adev, propname, if (ret)
index, &args); return ERR_PTR(ret);
if (ret) {
bool found = acpi_get_driver_gpio_data(adev, propname,
index, &args);
if (!found)
return ERR_PTR(ret);
}
/* dev_dbg(&adev->dev, "GPIO: _DSD returned %s %d %d %u\n",
* The property was found and resolved so need to dev_name(&lookup.adev->dev), lookup.index,
* lookup the GPIO based on returned args instead. lookup.pin_index, lookup.active_low);
*/
adev = args.adev;
if (args.nargs >= 2) {
lookup.index = args.args[0];
lookup.pin_index = args.args[1];
/*
* 3rd argument, if present is used to
* specify active_low.
*/
if (args.nargs >= 3)
active_low = !!args.args[2];
}
dev_dbg(&adev->dev, "GPIO: _DSD returned %s %zd %llu %llu %llu\n",
dev_name(&adev->dev), args.nargs,
args.args[0], args.args[1], args.args[2]);
} else { } else {
dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index); dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index);
lookup.adev = adev;
} }
INIT_LIST_HEAD(&resource_list); ret = acpi_gpio_resource_lookup(&lookup, info);
ret = acpi_dev_get_resources(adev, &resource_list, acpi_find_gpio, return ret ? ERR_PTR(ret) : lookup.desc;
&lookup);
if (ret < 0)
return ERR_PTR(ret);
acpi_dev_free_resource_list(&resource_list);
if (lookup.desc && info) {
*info = lookup.info;
if (active_low)
info->active_low = active_low;
}
return lookup.desc ? lookup.desc : ERR_PTR(-ENOENT);
} }
/** /**
......
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