2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-02-26 22:59:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2020-07-07 19:11:44 +00:00
|
|
|
#include <acpi/acpi_device.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <asm/gpio.h>
|
2020-09-11 08:13:35 +00:00
|
|
|
#include <dm/device-internal.h>
|
2014-10-04 17:29:51 +00:00
|
|
|
#include <dm/root.h>
|
2014-02-26 22:59:24 +00:00
|
|
|
#include <dm/test.h>
|
|
|
|
#include <dm/util.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <test/test.h>
|
2015-05-20 19:27:27 +00:00
|
|
|
#include <test/ut.h>
|
2014-02-26 22:59:24 +00:00
|
|
|
|
|
|
|
/* Test that sandbox GPIOs work correctly */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_gpio(struct unit_test_state *uts)
|
2014-02-26 22:59:24 +00:00
|
|
|
{
|
|
|
|
unsigned int offset, gpio;
|
|
|
|
struct dm_gpio_ops *ops;
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *dev;
|
2020-05-22 09:08:58 +00:00
|
|
|
struct gpio_desc *desc;
|
2014-02-26 22:59:24 +00:00
|
|
|
const char *name;
|
|
|
|
int offset_count;
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
/*
|
2020-01-13 10:35:14 +00:00
|
|
|
* We expect to get 4 banks. One is anonymous (just numbered) and
|
2020-12-03 23:55:18 +00:00
|
|
|
* comes from plat. The other are named a (20 gpios),
|
2020-01-13 10:35:14 +00:00
|
|
|
* b (10 gpios) and c (10 gpios) and come from the device tree. See
|
2014-02-26 22:59:24 +00:00
|
|
|
* test/dm/test.dts.
|
|
|
|
*/
|
|
|
|
ut_assertok(gpio_lookup_name("b4", &dev, &offset, &gpio));
|
|
|
|
ut_asserteq_str(dev->name, "extra-gpios");
|
|
|
|
ut_asserteq(4, offset);
|
|
|
|
ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 20 + 4, gpio);
|
|
|
|
|
|
|
|
name = gpio_get_bank_info(dev, &offset_count);
|
|
|
|
ut_asserteq_str("b", name);
|
|
|
|
ut_asserteq(10, offset_count);
|
|
|
|
|
|
|
|
/* Get the operations for this device */
|
|
|
|
ops = gpio_get_ops(dev);
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assert(ops->get_function);
|
2014-02-26 22:59:24 +00:00
|
|
|
|
|
|
|
/* Cannot get a value until it is reserved */
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_asserteq(-EBUSY, gpio_get_value(gpio + 1));
|
2014-02-26 22:59:24 +00:00
|
|
|
/*
|
|
|
|
* Now some tests that use the 'sandbox' back door. All GPIOs
|
|
|
|
* should default to input, include b4 that we are using here.
|
|
|
|
*/
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: input: 0 [ ]", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
|
|
|
|
/* Change it to an output */
|
|
|
|
sandbox_gpio_set_direction(dev, offset, 1);
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: output: 0 [ ]", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
|
|
|
|
sandbox_gpio_set_value(dev, offset, 1);
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: output: 1 [ ]", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_request(gpio, "testing"));
|
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: output: 1 [x] testing", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
|
|
|
|
/* Change the value a bit */
|
|
|
|
ut_asserteq(1, ops->get_value(dev, offset));
|
|
|
|
ut_assertok(ops->set_value(dev, offset, 0));
|
|
|
|
ut_asserteq(0, ops->get_value(dev, offset));
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: output: 0 [x] testing", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
ut_assertok(ops->set_value(dev, offset, 1));
|
|
|
|
ut_asserteq(1, ops->get_value(dev, offset));
|
|
|
|
|
2020-01-13 10:35:14 +00:00
|
|
|
/* Make it an open drain output, and reset it */
|
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE,
|
|
|
|
sandbox_gpio_get_dir_flags(dev, offset));
|
|
|
|
ut_assertok(ops->set_dir_flags(dev, offset,
|
|
|
|
GPIOD_IS_OUT | GPIOD_OPEN_DRAIN));
|
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_DRAIN,
|
|
|
|
sandbox_gpio_get_dir_flags(dev, offset));
|
|
|
|
ut_assertok(ops->set_dir_flags(dev, offset,
|
|
|
|
GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE));
|
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE,
|
|
|
|
sandbox_gpio_get_dir_flags(dev, offset));
|
|
|
|
|
2014-02-26 22:59:24 +00:00
|
|
|
/* Make it an input */
|
|
|
|
ut_assertok(ops->direction_input(dev, offset));
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: input: 1 [x] testing", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
sandbox_gpio_set_value(dev, offset, 0);
|
|
|
|
ut_asserteq(0, sandbox_gpio_get_value(dev, offset));
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: input: 0 [x] testing", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
|
2014-10-04 17:29:48 +00:00
|
|
|
ut_assertok(gpio_free(gpio));
|
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b4: input: 0 [ ]", buf);
|
2014-02-26 22:59:24 +00:00
|
|
|
|
|
|
|
/* Check the 'a' bank also */
|
|
|
|
ut_assertok(gpio_lookup_name("a15", &dev, &offset, &gpio));
|
|
|
|
ut_asserteq_str(dev->name, "base-gpios");
|
|
|
|
ut_asserteq(15, offset);
|
|
|
|
ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 15, gpio);
|
|
|
|
|
|
|
|
name = gpio_get_bank_info(dev, &offset_count);
|
|
|
|
ut_asserteq_str("a", name);
|
|
|
|
ut_asserteq(20, offset_count);
|
|
|
|
|
2020-05-22 09:08:58 +00:00
|
|
|
/* add gpio hog tests */
|
|
|
|
ut_assertok(gpio_hog_lookup_name("hog_input_active_low", &desc));
|
|
|
|
ut_asserteq(GPIOD_IS_IN | GPIOD_ACTIVE_LOW, desc->flags);
|
sandbox, test: change hog gpio
Since commit 9ba84329dc45 ("sandbox, test: add test for GPIO_HOG
function"), the gpio_a 0,1,2 and 3 are used by hog in test.dts.
But 2 leds 'sandbox:red' and 'sandbox:green' are using gpio_a 0
and 1. As hog always request his gpios, the led command on both
led is broken:
=> led sandbox:red
LED 'sandbox:red' not found (err=-16)
The gpio is already requested by hog, so it can't be enabled
for led 'sandbox:red'.
This commit change the gpio used by hog to 10, 11, 12 and 13,
so the led command could be used again with 'sandbox:red' and
'sandbox:green'.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
2020-07-24 13:51:53 +00:00
|
|
|
ut_asserteq(10, desc->offset);
|
2020-05-22 09:08:58 +00:00
|
|
|
ut_asserteq(1, dm_gpio_get_value(desc));
|
|
|
|
ut_assertok(gpio_hog_lookup_name("hog_input_active_high", &desc));
|
|
|
|
ut_asserteq(GPIOD_IS_IN, desc->flags);
|
sandbox, test: change hog gpio
Since commit 9ba84329dc45 ("sandbox, test: add test for GPIO_HOG
function"), the gpio_a 0,1,2 and 3 are used by hog in test.dts.
But 2 leds 'sandbox:red' and 'sandbox:green' are using gpio_a 0
and 1. As hog always request his gpios, the led command on both
led is broken:
=> led sandbox:red
LED 'sandbox:red' not found (err=-16)
The gpio is already requested by hog, so it can't be enabled
for led 'sandbox:red'.
This commit change the gpio used by hog to 10, 11, 12 and 13,
so the led command could be used again with 'sandbox:red' and
'sandbox:green'.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
2020-07-24 13:51:53 +00:00
|
|
|
ut_asserteq(11, desc->offset);
|
2020-05-22 09:08:58 +00:00
|
|
|
ut_asserteq(0, dm_gpio_get_value(desc));
|
|
|
|
ut_assertok(gpio_hog_lookup_name("hog_output_low", &desc));
|
|
|
|
ut_asserteq(GPIOD_IS_OUT, desc->flags);
|
sandbox, test: change hog gpio
Since commit 9ba84329dc45 ("sandbox, test: add test for GPIO_HOG
function"), the gpio_a 0,1,2 and 3 are used by hog in test.dts.
But 2 leds 'sandbox:red' and 'sandbox:green' are using gpio_a 0
and 1. As hog always request his gpios, the led command on both
led is broken:
=> led sandbox:red
LED 'sandbox:red' not found (err=-16)
The gpio is already requested by hog, so it can't be enabled
for led 'sandbox:red'.
This commit change the gpio used by hog to 10, 11, 12 and 13,
so the led command could be used again with 'sandbox:red' and
'sandbox:green'.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
2020-07-24 13:51:53 +00:00
|
|
|
ut_asserteq(12, desc->offset);
|
2020-05-22 09:08:58 +00:00
|
|
|
ut_asserteq(0, dm_gpio_get_value(desc));
|
|
|
|
ut_assertok(dm_gpio_set_value(desc, 1));
|
|
|
|
ut_asserteq(1, dm_gpio_get_value(desc));
|
|
|
|
ut_assertok(gpio_hog_lookup_name("hog_output_high", &desc));
|
|
|
|
ut_asserteq(GPIOD_IS_OUT, desc->flags);
|
sandbox, test: change hog gpio
Since commit 9ba84329dc45 ("sandbox, test: add test for GPIO_HOG
function"), the gpio_a 0,1,2 and 3 are used by hog in test.dts.
But 2 leds 'sandbox:red' and 'sandbox:green' are using gpio_a 0
and 1. As hog always request his gpios, the led command on both
led is broken:
=> led sandbox:red
LED 'sandbox:red' not found (err=-16)
The gpio is already requested by hog, so it can't be enabled
for led 'sandbox:red'.
This commit change the gpio used by hog to 10, 11, 12 and 13,
so the led command could be used again with 'sandbox:red' and
'sandbox:green'.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
2020-07-24 13:51:53 +00:00
|
|
|
ut_asserteq(13, desc->offset);
|
2020-05-22 09:08:58 +00:00
|
|
|
ut_asserteq(1, dm_gpio_get_value(desc));
|
|
|
|
ut_assertok(dm_gpio_set_value(desc, 0));
|
|
|
|
ut_asserteq(0, dm_gpio_get_value(desc));
|
|
|
|
|
2020-05-22 09:08:59 +00:00
|
|
|
/* Check if lookup for labels work */
|
|
|
|
ut_assertok(gpio_lookup_name("hog_input_active_low", &dev, &offset,
|
|
|
|
&gpio));
|
|
|
|
ut_asserteq_str(dev->name, "base-gpios");
|
sandbox, test: change hog gpio
Since commit 9ba84329dc45 ("sandbox, test: add test for GPIO_HOG
function"), the gpio_a 0,1,2 and 3 are used by hog in test.dts.
But 2 leds 'sandbox:red' and 'sandbox:green' are using gpio_a 0
and 1. As hog always request his gpios, the led command on both
led is broken:
=> led sandbox:red
LED 'sandbox:red' not found (err=-16)
The gpio is already requested by hog, so it can't be enabled
for led 'sandbox:red'.
This commit change the gpio used by hog to 10, 11, 12 and 13,
so the led command could be used again with 'sandbox:red' and
'sandbox:green'.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heiko Schocher <hs@denx.de>
2020-07-24 13:51:53 +00:00
|
|
|
ut_asserteq(10, offset);
|
|
|
|
ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 10, gpio);
|
2020-05-22 09:08:59 +00:00
|
|
|
ut_assert(gpio_lookup_name("hog_not_exist", &dev, &offset,
|
|
|
|
&gpio));
|
|
|
|
|
2014-10-04 17:29:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-10-04 17:29:48 +00:00
|
|
|
|
2020-05-05 08:43:18 +00:00
|
|
|
/* Test that GPIO open-drain/open-source emulation works correctly */
|
|
|
|
static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct gpio_desc desc_list[8];
|
|
|
|
struct udevice *dev, *gpio_c;
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_GPIO, 3, &gpio_c));
|
|
|
|
ut_asserteq_str("pinmux-gpios", gpio_c->name);
|
|
|
|
|
|
|
|
ut_asserteq(8, gpio_request_list_by_name(dev, "test3-gpios", desc_list,
|
|
|
|
ARRAY_SIZE(desc_list), 0))
|
|
|
|
|
|
|
|
ut_asserteq(true, !!device_active(gpio_c));
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[0].dev);
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[1].dev);
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[2].dev);
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[3].dev);
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[4].dev);
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[5].dev);
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[6].dev);
|
|
|
|
ut_asserteq_ptr(gpio_c, desc_list[7].dev);
|
|
|
|
|
|
|
|
/* GPIO 0 is (GPIO_OUT|GPIO_OPEN_DRAIN) */
|
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_DRAIN,
|
|
|
|
sandbox_gpio_get_dir_flags(gpio_c, 0));
|
|
|
|
|
|
|
|
/* Set it as output high, should become an input */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[0], 1));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 0, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c0: input: 0 [x] a-test.test3-gpios0", buf);
|
|
|
|
|
|
|
|
/* Set it as output low, should become output low */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[0], 0));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 0, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c0: output: 0 [x] a-test.test3-gpios0", buf);
|
|
|
|
|
|
|
|
/* GPIO 1 is (GPIO_OUT|GPIO_OPEN_SOURCE) */
|
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_SOURCE,
|
|
|
|
sandbox_gpio_get_dir_flags(gpio_c, 1));
|
|
|
|
|
|
|
|
/* Set it as output high, should become output high */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[1], 1));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 1, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c1: output: 1 [x] a-test.test3-gpios1", buf);
|
|
|
|
|
|
|
|
/* Set it as output low, should become an input */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[1], 0));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 1, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c1: input: 1 [x] a-test.test3-gpios1", buf);
|
|
|
|
|
|
|
|
/* GPIO 6 is (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_DRAIN) */
|
|
|
|
ut_asserteq(GPIOD_ACTIVE_LOW | GPIOD_IS_OUT | GPIOD_OPEN_DRAIN,
|
|
|
|
sandbox_gpio_get_dir_flags(gpio_c, 6));
|
|
|
|
|
|
|
|
/* Set it as output high, should become output low */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[6], 1));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 6, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c6: output: 0 [x] a-test.test3-gpios6", buf);
|
|
|
|
|
|
|
|
/* Set it as output low, should become an input */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[6], 0));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 6, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c6: input: 0 [x] a-test.test3-gpios6", buf);
|
|
|
|
|
|
|
|
/* GPIO 7 is (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_SOURCE) */
|
|
|
|
ut_asserteq(GPIOD_ACTIVE_LOW | GPIOD_IS_OUT | GPIOD_OPEN_SOURCE,
|
|
|
|
sandbox_gpio_get_dir_flags(gpio_c, 7));
|
|
|
|
|
|
|
|
/* Set it as output high, should become an input */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[7], 1));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 7, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c7: input: 0 [x] a-test.test3-gpios7", buf);
|
|
|
|
|
|
|
|
/* Set it as output low, should become output high */
|
|
|
|
ut_assertok(dm_gpio_set_value(&desc_list[7], 0));
|
|
|
|
ut_assertok(gpio_get_status(gpio_c, 7, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("c7: output: 1 [x] a-test.test3-gpios7", buf);
|
|
|
|
|
|
|
|
ut_assertok(gpio_free_list(dev, desc_list, 8));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_gpio_opendrain_opensource,
|
2020-07-29 01:41:12 +00:00
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-05-05 08:43:18 +00:00
|
|
|
|
2014-10-04 17:29:48 +00:00
|
|
|
/* Test that sandbox anonymous GPIOs work correctly */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_gpio_anon(struct unit_test_state *uts)
|
2014-10-04 17:29:48 +00:00
|
|
|
{
|
|
|
|
unsigned int offset, gpio;
|
|
|
|
struct udevice *dev;
|
|
|
|
const char *name;
|
|
|
|
int offset_count;
|
|
|
|
|
2014-02-26 22:59:24 +00:00
|
|
|
/* And the anonymous bank */
|
|
|
|
ut_assertok(gpio_lookup_name("14", &dev, &offset, &gpio));
|
2020-06-25 04:10:04 +00:00
|
|
|
ut_asserteq_str(dev->name, "sandbox_gpio");
|
2014-02-26 22:59:24 +00:00
|
|
|
ut_asserteq(14, offset);
|
|
|
|
ut_asserteq(14, gpio);
|
|
|
|
|
|
|
|
name = gpio_get_bank_info(dev, &offset_count);
|
|
|
|
ut_asserteq_ptr(NULL, name);
|
|
|
|
ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT, offset_count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_anon, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-10-04 17:29:49 +00:00
|
|
|
|
|
|
|
/* Test that gpio_requestf() works as expected */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_gpio_requestf(struct unit_test_state *uts)
|
2014-10-04 17:29:49 +00:00
|
|
|
{
|
|
|
|
unsigned int offset, gpio;
|
|
|
|
struct udevice *dev;
|
|
|
|
char buf[80];
|
|
|
|
|
|
|
|
ut_assertok(gpio_lookup_name("b5", &dev, &offset, &gpio));
|
|
|
|
ut_assertok(gpio_requestf(gpio, "testing %d %s", 1, "hi"));
|
|
|
|
sandbox_gpio_set_direction(dev, offset, 1);
|
|
|
|
sandbox_gpio_set_value(dev, offset, 1);
|
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b5: output: 1 [x] testing 1 hi", buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_requestf, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-10-04 17:29:51 +00:00
|
|
|
|
|
|
|
/* Test that gpio_request() copies its string */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_gpio_copy(struct unit_test_state *uts)
|
2014-10-04 17:29:51 +00:00
|
|
|
{
|
|
|
|
unsigned int offset, gpio;
|
|
|
|
struct udevice *dev;
|
|
|
|
char buf[80], name[10];
|
|
|
|
|
|
|
|
ut_assertok(gpio_lookup_name("b6", &dev, &offset, &gpio));
|
|
|
|
strcpy(name, "odd_name");
|
|
|
|
ut_assertok(gpio_request(gpio, name));
|
|
|
|
sandbox_gpio_set_direction(dev, offset, 1);
|
|
|
|
sandbox_gpio_set_value(dev, offset, 1);
|
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
|
|
|
|
strcpy(name, "nothing");
|
|
|
|
ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
|
|
|
|
ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_copy, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-10-04 17:29:51 +00:00
|
|
|
|
|
|
|
/* Test that we don't leak memory with GPIOs */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_gpio_leak(struct unit_test_state *uts)
|
2014-10-04 17:29:51 +00:00
|
|
|
{
|
2015-05-20 19:27:27 +00:00
|
|
|
ut_assertok(dm_test_gpio(uts));
|
|
|
|
ut_assertok(dm_test_gpio_anon(uts));
|
|
|
|
ut_assertok(dm_test_gpio_requestf(uts));
|
|
|
|
ut_assertok(dm_leak_check_end(uts));
|
2014-10-04 17:29:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_leak, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.
Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:
gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
This will request the GPIO, looking at the device's node which might be
this, for example:
cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.
It is also possible to request and free a list of GPIOs.
Signed-off-by: Simon Glass <sjg@chromium.org>
2015-01-06 03:05:29 +00:00
|
|
|
|
|
|
|
/* Test that we can find GPIOs using phandles */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_gpio_phandles(struct unit_test_state *uts)
|
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.
Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:
gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
This will request the GPIO, looking at the device's node which might be
this, for example:
cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.
It is also possible to request and free a list of GPIOs.
Signed-off-by: Simon Glass <sjg@chromium.org>
2015-01-06 03:05:29 +00:00
|
|
|
{
|
|
|
|
struct gpio_desc desc, desc_list[8], desc_list2[8];
|
|
|
|
struct udevice *dev, *gpio_a, *gpio_b;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
|
|
|
|
ut_assertok(gpio_request_by_name(dev, "test-gpios", 1, &desc, 0));
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio_a));
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_GPIO, 2, &gpio_b));
|
|
|
|
ut_asserteq_str("base-gpios", gpio_a->name);
|
|
|
|
ut_asserteq(true, !!device_active(gpio_a));
|
|
|
|
ut_asserteq_ptr(gpio_a, desc.dev);
|
|
|
|
ut_asserteq(4, desc.offset);
|
|
|
|
/* GPIOF_INPUT is the sandbox GPIO driver default */
|
|
|
|
ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_a, 4, NULL));
|
|
|
|
ut_assertok(dm_gpio_free(dev, &desc));
|
|
|
|
|
|
|
|
ut_asserteq(-ENOENT, gpio_request_by_name(dev, "test-gpios", 3, &desc,
|
|
|
|
0));
|
|
|
|
ut_asserteq_ptr(NULL, desc.dev);
|
|
|
|
ut_asserteq(desc.offset, 0);
|
|
|
|
ut_asserteq(-ENOENT, gpio_request_by_name(dev, "test-gpios", 5, &desc,
|
|
|
|
0));
|
|
|
|
|
|
|
|
/* Last GPIO is ignord as it comes after <0> */
|
|
|
|
ut_asserteq(3, gpio_request_list_by_name(dev, "test-gpios", desc_list,
|
|
|
|
ARRAY_SIZE(desc_list), 0));
|
|
|
|
ut_asserteq(-EBUSY, gpio_request_list_by_name(dev, "test-gpios",
|
|
|
|
desc_list2,
|
|
|
|
ARRAY_SIZE(desc_list2),
|
|
|
|
0));
|
2020-01-13 10:35:14 +00:00
|
|
|
ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_a, 4, NULL));
|
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.
Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:
gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
This will request the GPIO, looking at the device's node which might be
this, for example:
cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.
It is also possible to request and free a list of GPIOs.
Signed-off-by: Simon Glass <sjg@chromium.org>
2015-01-06 03:05:29 +00:00
|
|
|
ut_assertok(gpio_free_list(dev, desc_list, 3));
|
2020-01-13 10:35:14 +00:00
|
|
|
ut_asserteq(GPIOF_UNUSED, gpio_get_function(gpio_a, 4, NULL));
|
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.
Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:
gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
This will request the GPIO, looking at the device's node which might be
this, for example:
cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.
It is also possible to request and free a list of GPIOs.
Signed-off-by: Simon Glass <sjg@chromium.org>
2015-01-06 03:05:29 +00:00
|
|
|
ut_asserteq(3, gpio_request_list_by_name(dev, "test-gpios", desc_list,
|
|
|
|
ARRAY_SIZE(desc_list),
|
|
|
|
GPIOD_IS_OUT |
|
|
|
|
GPIOD_IS_OUT_ACTIVE));
|
2020-01-13 10:35:14 +00:00
|
|
|
ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_a, 4, NULL));
|
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.
Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:
gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
This will request the GPIO, looking at the device's node which might be
this, for example:
cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.
It is also possible to request and free a list of GPIOs.
Signed-off-by: Simon Glass <sjg@chromium.org>
2015-01-06 03:05:29 +00:00
|
|
|
ut_asserteq_ptr(gpio_a, desc_list[0].dev);
|
|
|
|
ut_asserteq(1, desc_list[0].offset);
|
|
|
|
ut_asserteq_ptr(gpio_a, desc_list[1].dev);
|
|
|
|
ut_asserteq(4, desc_list[1].offset);
|
|
|
|
ut_asserteq_ptr(gpio_b, desc_list[2].dev);
|
|
|
|
ut_asserteq(5, desc_list[2].offset);
|
|
|
|
ut_asserteq(1, dm_gpio_get_value(desc_list));
|
|
|
|
ut_assertok(gpio_free_list(dev, desc_list, 3));
|
|
|
|
|
2020-01-13 10:35:14 +00:00
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE,
|
|
|
|
sandbox_gpio_get_dir_flags(gpio_a, 1));
|
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.
Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:
gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
This will request the GPIO, looking at the device's node which might be
this, for example:
cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.
It is also possible to request and free a list of GPIOs.
Signed-off-by: Simon Glass <sjg@chromium.org>
2015-01-06 03:05:29 +00:00
|
|
|
ut_asserteq(6, gpio_request_list_by_name(dev, "test2-gpios", desc_list,
|
|
|
|
ARRAY_SIZE(desc_list), 0));
|
2020-01-13 10:35:14 +00:00
|
|
|
|
|
|
|
/* This was set to output previously but flags resetted to 0 = INPUT */
|
|
|
|
ut_asserteq(0, sandbox_gpio_get_dir_flags(gpio_a, 1));
|
|
|
|
ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_a, 1, NULL));
|
dm: gpio: Add better functions to request GPIOs
At present U-Boot sort-of supports the standard way of reading GPIOs from
device tree nodes, but the support is incomplete, a bit clunky and only
works for GPIO bindings where #gpio-cells is 2.
Add new functions to request GPIOs, taking full account of the device
tree binding. These permit requesting a GPIO with a simple call like:
gpio_request_by_name(dev, "cd-gpios", 0, &desc, GPIOD_IS_IN);
This will request the GPIO, looking at the device's node which might be
this, for example:
cd-gpios = <&gpio TEGRA_GPIO(B, 3) GPIO_ACTIVE_LOW>;
The GPIO will be set to input mode in this case and polarity will be
honoured by the GPIO calls.
It is also possible to request and free a list of GPIOs.
Signed-off-by: Simon Glass <sjg@chromium.org>
2015-01-06 03:05:29 +00:00
|
|
|
|
|
|
|
/* Active low should invert the input value */
|
|
|
|
ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_b, 6, NULL));
|
|
|
|
ut_asserteq(1, dm_gpio_get_value(&desc_list[2]));
|
|
|
|
|
|
|
|
ut_asserteq(GPIOF_INPUT, gpio_get_function(gpio_b, 7, NULL));
|
|
|
|
ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_b, 8, NULL));
|
|
|
|
ut_asserteq(0, dm_gpio_get_value(&desc_list[4]));
|
|
|
|
ut_asserteq(GPIOF_OUTPUT, gpio_get_function(gpio_b, 9, NULL));
|
|
|
|
ut_asserteq(1, dm_gpio_get_value(&desc_list[5]));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_phandles, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-01-13 10:35:14 +00:00
|
|
|
|
|
|
|
/* Check the gpio pin configuration get from device tree information */
|
|
|
|
static int dm_test_gpio_get_dir_flags(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct gpio_desc desc_list[6];
|
|
|
|
struct udevice *dev;
|
|
|
|
ulong flags;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
|
|
|
|
|
|
|
|
ut_asserteq(6, gpio_request_list_by_name(dev, "test3-gpios", desc_list,
|
|
|
|
ARRAY_SIZE(desc_list), 0));
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_get_dir_flags(&desc_list[0], &flags));
|
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_DRAIN, flags);
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_get_dir_flags(&desc_list[1], &flags));
|
|
|
|
ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_SOURCE, flags);
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_get_dir_flags(&desc_list[2], &flags));
|
|
|
|
ut_asserteq(GPIOD_IS_OUT, flags);
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_get_dir_flags(&desc_list[3], &flags));
|
|
|
|
ut_asserteq(GPIOD_IS_IN | GPIOD_PULL_UP, flags);
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_get_dir_flags(&desc_list[4], &flags));
|
|
|
|
ut_asserteq(GPIOD_IS_IN | GPIOD_PULL_DOWN, flags);
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_get_dir_flags(&desc_list[5], &flags));
|
|
|
|
ut_asserteq(GPIOD_IS_IN, flags);
|
|
|
|
|
|
|
|
ut_assertok(gpio_free_list(dev, desc_list, 6));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_get_dir_flags, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-07-07 19:11:44 +00:00
|
|
|
|
|
|
|
/* Test of gpio_get_acpi() */
|
|
|
|
static int dm_test_gpio_get_acpi(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct acpi_gpio agpio;
|
|
|
|
struct udevice *dev;
|
|
|
|
struct gpio_desc desc;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
ut_assertok(gpio_request_by_name(dev, "test-gpios", 1, &desc, 0));
|
|
|
|
|
|
|
|
/* See sb_gpio_get_acpi() */
|
|
|
|
ut_assertok(gpio_get_acpi(&desc, &agpio));
|
|
|
|
ut_asserteq(1, agpio.pin_count);
|
|
|
|
ut_asserteq(4, agpio.pins[0]);
|
|
|
|
ut_asserteq(ACPI_GPIO_TYPE_IO, agpio.type);
|
|
|
|
ut_asserteq(ACPI_GPIO_PULL_UP, agpio.pull);
|
|
|
|
ut_asserteq_str("\\_SB.PINC", agpio.resource);
|
|
|
|
ut_asserteq(0, agpio.interrupt_debounce_timeout);
|
|
|
|
ut_asserteq(0, agpio.irq.pin);
|
|
|
|
ut_asserteq(1234, agpio.output_drive_strength);
|
|
|
|
ut_asserteq(true, agpio.io_shared);
|
|
|
|
ut_asserteq(ACPI_GPIO_IO_RESTRICT_INPUT, agpio.io_restrict);
|
|
|
|
ut_asserteq(ACPI_GPIO_ACTIVE_HIGH, agpio.polarity);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_get_acpi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-07-07 19:11:44 +00:00
|
|
|
|
|
|
|
/* Test of gpio_get_acpi() with an interrupt GPIO */
|
|
|
|
static int dm_test_gpio_get_acpi_irq(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct acpi_gpio agpio;
|
|
|
|
struct udevice *dev;
|
|
|
|
struct gpio_desc desc;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
|
|
|
|
ut_asserteq_str("a-test", dev->name);
|
|
|
|
ut_assertok(gpio_request_by_name(dev, "test2-gpios", 2, &desc, 0));
|
|
|
|
|
|
|
|
/* See sb_gpio_get_acpi() */
|
|
|
|
ut_assertok(gpio_get_acpi(&desc, &agpio));
|
|
|
|
ut_asserteq(1, agpio.pin_count);
|
|
|
|
ut_asserteq(6, agpio.pins[0]);
|
|
|
|
ut_asserteq(ACPI_GPIO_TYPE_INTERRUPT, agpio.type);
|
|
|
|
ut_asserteq(ACPI_GPIO_PULL_DOWN, agpio.pull);
|
|
|
|
ut_asserteq_str("\\_SB.PINC", agpio.resource);
|
|
|
|
ut_asserteq(4321, agpio.interrupt_debounce_timeout);
|
|
|
|
ut_asserteq(6, agpio.irq.pin);
|
|
|
|
ut_asserteq(ACPI_IRQ_ACTIVE_BOTH, agpio.irq.polarity);
|
|
|
|
ut_asserteq(ACPI_IRQ_SHARED, agpio.irq.shared);
|
|
|
|
ut_asserteq(true, agpio.irq.wake);
|
|
|
|
ut_asserteq(0, agpio.output_drive_strength);
|
|
|
|
ut_asserteq(false, agpio.io_shared);
|
|
|
|
ut_asserteq(0, agpio.io_restrict);
|
|
|
|
ut_asserteq(ACPI_GPIO_ACTIVE_LOW, agpio.polarity);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_gpio_get_acpi_irq, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-09-11 08:13:35 +00:00
|
|
|
|
|
|
|
/* Test that we can get/release GPIOs using managed API */
|
|
|
|
static int dm_test_gpio_devm(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
static const u32 flags = GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE;
|
|
|
|
struct gpio_desc *desc1, *desc2, *desc3, *desc_err;
|
|
|
|
struct udevice *dev;
|
|
|
|
struct udevice *dev2;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test",
|
|
|
|
&dev));
|
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "another-test",
|
|
|
|
&dev2));
|
|
|
|
|
|
|
|
/* Get 3 GPIOs from 'a-test' dev */
|
|
|
|
desc1 = devm_gpiod_get_index(dev, "test4", 0, flags);
|
|
|
|
ut_assert(!IS_ERR(desc1));
|
|
|
|
desc2 = devm_gpiod_get_index(dev, "test4", 1, flags);
|
|
|
|
ut_assert(!IS_ERR(desc2));
|
|
|
|
desc3 = devm_gpiod_get_index_optional(dev, "test5", 0, flags);
|
|
|
|
ut_assert(!IS_ERR(desc3));
|
|
|
|
ut_assert(desc3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try get the same 3 GPIOs from 'a-test' and 'another-test' devices.
|
|
|
|
* check that it fails
|
|
|
|
*/
|
|
|
|
desc_err = devm_gpiod_get_index(dev, "test4", 0, flags);
|
|
|
|
ut_asserteq(-EBUSY, PTR_ERR(desc_err));
|
|
|
|
desc_err = devm_gpiod_get_index(dev2, "test4", 0, flags);
|
|
|
|
ut_asserteq(-EBUSY, PTR_ERR(desc_err));
|
|
|
|
desc_err = devm_gpiod_get_index(dev, "test4", 1, flags);
|
|
|
|
ut_asserteq(-EBUSY, PTR_ERR(desc_err));
|
|
|
|
desc_err = devm_gpiod_get_index(dev2, "test4", 1, flags);
|
|
|
|
ut_asserteq(-EBUSY, PTR_ERR(desc_err));
|
|
|
|
desc_err = devm_gpiod_get_index_optional(dev, "test5", 0, flags);
|
|
|
|
ut_asserteq_ptr(NULL, desc_err);
|
|
|
|
desc_err = devm_gpiod_get_index_optional(dev2, "test5", 0, flags);
|
|
|
|
ut_asserteq_ptr(NULL, desc_err);
|
|
|
|
|
|
|
|
/* Try get GPIOs outside of the list */
|
|
|
|
desc_err = devm_gpiod_get_index(dev, "test4", 2, flags);
|
|
|
|
ut_assert(IS_ERR(desc_err));
|
|
|
|
desc_err = devm_gpiod_get_index_optional(dev, "test5", 1, flags);
|
|
|
|
ut_asserteq_ptr(NULL, desc_err);
|
|
|
|
|
|
|
|
/* Manipulate the GPIOs */
|
|
|
|
ut_assertok(dm_gpio_set_value(desc1, 1));
|
|
|
|
ut_asserteq(1, dm_gpio_get_value(desc1));
|
|
|
|
ut_assertok(dm_gpio_set_value(desc1, 0));
|
|
|
|
ut_asserteq(0, dm_gpio_get_value(desc1));
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_set_value(desc2, 1));
|
|
|
|
ut_asserteq(1, dm_gpio_get_value(desc2));
|
|
|
|
ut_assertok(dm_gpio_set_value(desc2, 0));
|
|
|
|
ut_asserteq(0, dm_gpio_get_value(desc2));
|
|
|
|
|
|
|
|
ut_assertok(dm_gpio_set_value(desc3, 1));
|
|
|
|
ut_asserteq(1, dm_gpio_get_value(desc3));
|
|
|
|
ut_assertok(dm_gpio_set_value(desc3, 0));
|
|
|
|
ut_asserteq(0, dm_gpio_get_value(desc3));
|
|
|
|
|
|
|
|
/* Check that the GPIO cannot be owned by more than one device */
|
|
|
|
desc_err = devm_gpiod_get_index(dev2, "test4", 0, flags);
|
|
|
|
ut_asserteq(-EBUSY, PTR_ERR(desc_err));
|
|
|
|
desc_err = devm_gpiod_get_index(dev2, "test4", 1, flags);
|
|
|
|
ut_asserteq(-EBUSY, PTR_ERR(desc_err));
|
|
|
|
desc_err = devm_gpiod_get_index_optional(dev2, "test5", 0, flags);
|
|
|
|
ut_asserteq_ptr(NULL, desc_err);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release one GPIO and check that we can get it back using
|
|
|
|
* 'another-test' and then 'a-test'
|
|
|
|
*/
|
|
|
|
devm_gpiod_put(dev, desc2);
|
|
|
|
desc2 = devm_gpiod_get_index(dev2, "test4", 1, flags);
|
|
|
|
ut_assert(!IS_ERR(desc2));
|
|
|
|
|
|
|
|
devm_gpiod_put(dev2, desc2);
|
|
|
|
desc2 = devm_gpiod_get_index(dev, "test4", 1, flags);
|
|
|
|
ut_assert(!IS_ERR(desc2));
|
|
|
|
|
|
|
|
/* Release one GPIO before removing the 'a-test' dev. */
|
|
|
|
devm_gpiod_put(dev, desc2);
|
|
|
|
device_remove(dev, DM_REMOVE_NORMAL);
|
|
|
|
|
|
|
|
/* All the GPIOs must have been freed. We should be able to claim
|
|
|
|
* them with the 'another-test' device.
|
|
|
|
*/
|
|
|
|
desc1 = devm_gpiod_get_index(dev2, "test4", 0, flags);
|
|
|
|
ut_assert(!IS_ERR(desc1));
|
|
|
|
desc2 = devm_gpiod_get_index(dev2, "test4", 1, flags);
|
|
|
|
ut_assert(!IS_ERR(desc2));
|
|
|
|
desc3 = devm_gpiod_get_index_optional(dev2, "test5", 0, flags);
|
|
|
|
ut_assert(!IS_ERR(desc3));
|
|
|
|
ut_assert(desc3);
|
|
|
|
|
|
|
|
device_remove(dev2, DM_REMOVE_NORMAL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_gpio_devm, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|