From 6d43be3a51d28c83f60c99ab023fc4a3472f7942 Mon Sep 17 00:00:00 2001 From: Ondrej Jirman Date: Thu, 3 Dec 2020 20:00:41 +0100 Subject: [PATCH 279/478] misc: modem-power: GPIO debugging API Signed-off-by: Ondrej Jirman --- drivers/misc/modem-power.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/misc/modem-power.c b/drivers/misc/modem-power.c index 91d2bfdd163e..0a5f37eb4208 100644 --- a/drivers/misc/modem-power.c +++ b/drivers/misc/modem-power.c @@ -1300,12 +1300,45 @@ static ssize_t hard_reset_store(struct device *dev, return len; } +static ssize_t debug_pins_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct mpwr_dev *mpwr = platform_get_drvdata(to_platform_device(dev)); + unsigned val; + int ret; + + if (test_bit(MPWR_F_BLOCKED, mpwr->flags)) + return -EPERM; + + ret = kstrtouint(buf, 16, &val); + if (ret) + return ret; + + gpiod_direction_output(mpwr->host_ready_gpio, val & BIT(0)); + gpiod_direction_output(mpwr->enable_gpio, val & BIT(1)); + gpiod_direction_output(mpwr->dtr_gpio, val & BIT(2)); + gpiod_direction_output(mpwr->rts_gpio, val & BIT(3)); + + return len; +} + +static ssize_t debug_pins_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mpwr_dev *mpwr = platform_get_drvdata(to_platform_device(dev)); + + return scnprintf(buf, PAGE_SIZE, "CTS=%u RI=%u\n", + gpiod_get_value(mpwr->cts_gpio), gpiod_get_value(mpwr->wakeup_gpio)); +} + static DEVICE_ATTR_RW(powered); static DEVICE_ATTR_WO(powered_blocking); static DEVICE_ATTR_RO(killswitched); static DEVICE_ATTR_RO(is_busy); static DEVICE_ATTR_RO(help); static DEVICE_ATTR_WO(hard_reset); +static DEVICE_ATTR_RW(debug_pins); static struct attribute *mpwr_attrs[] = { &dev_attr_powered.attr, @@ -1314,6 +1347,7 @@ static struct attribute *mpwr_attrs[] = { &dev_attr_is_busy.attr, &dev_attr_help.attr, &dev_attr_hard_reset.attr, + &dev_attr_debug_pins.attr, NULL, }; -- 2.35.3