From 771c9199b66d0eadc7587cf61f00256df49188d2 Mon Sep 17 00:00:00 2001 From: Harsh Sharma Date: Thu, 24 Mar 2022 17:05:56 -0500 Subject: Update mts-io to use gpiod for MTCAP3 --- io-module/mts-io.c | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'io-module/mts-io.c') diff --git a/io-module/mts-io.c b/io-module/mts-io.c index a6e5204..970e6b3 100644 --- a/io-module/mts-io.c +++ b/io-module/mts-io.c @@ -47,6 +47,8 @@ #include "at91gpio.h" #include "mts_io_module.h" #include "version.h" +#include "config.h" + #include "mts_io.h" #include "buttons.h" #include "mts_supercap.h" @@ -1410,7 +1412,7 @@ static int __init mts_io_init(void) int ret; - log_info("init: " DRIVER_VERSION); + log_info("init: " VERSION); /* We do a platform_driver_register to do a probe * of device tree and set the pinctrl/gpio settings. */ @@ -1475,11 +1477,25 @@ static int __init mts_io_init(void) for (pin = gpio_pins; *pin->name; pin++) { if (pin->capability == 0 || DEVICE_CAPA(id_eeprom.capa,pin->capability)) { - ret = gpio_request_one(pin->pin.gpio, pin->pin.flags, pin->pin.label); - if (ret) - dev_dbg(&mts_io_platform_device->dev, - "could not request pin %s (%d) but it could have already been requested under a different pin name", - pin->name, ret); + if (pin->do_gpio_desc) { + dev_dbg(&mts_io_platform_device->dev,"Request name:%s label: %s\n", pin->name, pin->pin.label); + pin->desc = devm_gpiod_get_optional(&mts_io_platform_device->dev, pin->name, pin->pin.flags); + if (IS_ERR(pin->desc)) { + log_warning( + "%s: Could not get gpio %s: Error: %ld\n", __func__, pin->name, PTR_ERR(pin->desc)); + } else { + if (pin->desc == NULL) + dev_dbg(&mts_io_platform_device->dev,"gpio_desc is null for name: %s, label: %s\n", + pin->name, pin->pin.label); + else + dev_dbg(&mts_io_platform_device->dev,"Found gpio %s\n", pin->name); + } + } else { + dev_dbg(&mts_io_platform_device->dev,"Request name:%s label: %s pin: %d\n", pin->name, pin->pin.label, pin->pin.gpio); + ret = gpio_request_one(pin->pin.gpio, pin->pin.flags, pin->pin.label); + if (ret) + log_warning("could not request pin %s (%d) but it could have already been requested under a different pin name\n", pin->name, ret); + } } } @@ -1521,9 +1537,15 @@ static void __exit mts_io_exit(void) /* delete radio_reset_available_timer */ del_timer(&radio_reset_available_timer); - for (pin = gpio_pins; *pin->name; pin++) - if (pin->capability == 0 || DEVICE_CAPA(id_eeprom.capa,pin->capability)) - gpio_free(pin->pin.gpio); + for (pin = gpio_pins; *pin->name; pin++) { + if (pin->capability == 0 || DEVICE_CAPA(id_eeprom.capa,pin->capability)) { + if (pin->do_gpio_desc) { + gpiod_put(pin->desc); + } else { + gpio_free(pin->pin.gpio); + } + } + } cleanup_buttons(); @@ -1549,5 +1571,5 @@ module_exit(mts_io_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); -MODULE_VERSION(DRIVER_VERSION); +MODULE_VERSION(VERSION); MODULE_LICENSE("GPL"); -- cgit v1.2.3