net: rfkill: gpio: Add default GPIO driver mappings for ACPI

The driver uses devm_gpiod_get_index(..., index) so that the index refers
directly to the GpioIo resource under the ACPI device. The problem with
this is that if the ordering changes we get wrong GPIOs.

With ACPI 5.1 _DSD we can now use names instead to reference GPIOs
analogous to Device Tree. However, we still have systems out there that do
not provide _DSD at all. These systems must be supported as well.

Luckily we now have acpi_dev_add_driver_gpios() that can be used to provide
mappings for systems where _DSD is not provided and still take advantage of
_DSD if it exists.

This patch changes the driver to create default GPIO mappings if we are
running on ACPI system.

While there we can drop the indices completely and use devm_gpiod_get()
with name instead.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Johannes Berg <johannes@sipsolutions.net>
Acked-by: John W. Linville <linville@tuxdriver.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Mika Westerberg 2014-10-27 12:15:14 +02:00 коммит произвёл Rafael J. Wysocki
Родитель f028d5242d
Коммит 72daceb9a1
1 изменённых файлов: 15 добавлений и 3 удалений

Просмотреть файл

@ -63,6 +63,15 @@ static const struct rfkill_ops rfkill_gpio_ops = {
.set_block = rfkill_gpio_set_power, .set_block = rfkill_gpio_set_power,
}; };
static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
static const struct acpi_gpio_params shutdown_gpios = { 1, 0, false };
static const struct acpi_gpio_mapping acpi_rfkill_default_gpios[] = {
{ "reset-gpios", &reset_gpios, 1 },
{ "shutdown-gpios", &shutdown_gpios, 1 },
{ },
};
static int rfkill_gpio_acpi_probe(struct device *dev, static int rfkill_gpio_acpi_probe(struct device *dev,
struct rfkill_gpio_data *rfkill) struct rfkill_gpio_data *rfkill)
{ {
@ -75,7 +84,8 @@ static int rfkill_gpio_acpi_probe(struct device *dev,
rfkill->name = dev_name(dev); rfkill->name = dev_name(dev);
rfkill->type = (unsigned)id->driver_data; rfkill->type = (unsigned)id->driver_data;
return 0; return acpi_dev_add_driver_gpios(ACPI_COMPANION(dev),
acpi_rfkill_default_gpios);
} }
static int rfkill_gpio_probe(struct platform_device *pdev) static int rfkill_gpio_probe(struct platform_device *pdev)
@ -102,7 +112,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
rfkill->clk = devm_clk_get(&pdev->dev, NULL); rfkill->clk = devm_clk_get(&pdev->dev, NULL);
gpio = devm_gpiod_get_index(&pdev->dev, "reset", 0); gpio = devm_gpiod_get(&pdev->dev, "reset");
if (!IS_ERR(gpio)) { if (!IS_ERR(gpio)) {
ret = gpiod_direction_output(gpio, 0); ret = gpiod_direction_output(gpio, 0);
if (ret) if (ret)
@ -110,7 +120,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
rfkill->reset_gpio = gpio; rfkill->reset_gpio = gpio;
} }
gpio = devm_gpiod_get_index(&pdev->dev, "shutdown", 1); gpio = devm_gpiod_get(&pdev->dev, "shutdown");
if (!IS_ERR(gpio)) { if (!IS_ERR(gpio)) {
ret = gpiod_direction_output(gpio, 0); ret = gpiod_direction_output(gpio, 0);
if (ret) if (ret)
@ -150,6 +160,8 @@ static int rfkill_gpio_remove(struct platform_device *pdev)
rfkill_unregister(rfkill->rfkill_dev); rfkill_unregister(rfkill->rfkill_dev);
rfkill_destroy(rfkill->rfkill_dev); rfkill_destroy(rfkill->rfkill_dev);
acpi_dev_remove_driver_gpios(ACPI_COMPANION(&pdev->dev));
return 0; return 0;
} }