mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 06:31:31 +00:00
dm: gpio: Add gpio_requestf() helper for printf() strings
Add a helper which permits a printf()-style format string for the requester string. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
4b8f11c2cc
commit
d44f597b12
4 changed files with 51 additions and 1 deletions
|
@ -95,7 +95,7 @@ are provided in test/dm. To run them, try:
|
||||||
You should see something like this:
|
You should see something like this:
|
||||||
|
|
||||||
<...U-Boot banner...>
|
<...U-Boot banner...>
|
||||||
Running 26 driver model tests
|
Running 27 driver model tests
|
||||||
Test: dm_test_autobind
|
Test: dm_test_autobind
|
||||||
Test: dm_test_autoprobe
|
Test: dm_test_autoprobe
|
||||||
Test: dm_test_bus_children
|
Test: dm_test_bus_children
|
||||||
|
@ -117,6 +117,7 @@ You should see something like this:
|
||||||
Test: dm_test_gpio
|
Test: dm_test_gpio
|
||||||
extra-gpios: get_value: error: gpio b5 not reserved
|
extra-gpios: get_value: error: gpio b5 not reserved
|
||||||
Test: dm_test_gpio_anon
|
Test: dm_test_gpio_anon
|
||||||
|
Test: dm_test_gpio_requestf
|
||||||
Test: dm_test_leak
|
Test: dm_test_leak
|
||||||
Test: dm_test_lifecycle
|
Test: dm_test_lifecycle
|
||||||
Test: dm_test_operations
|
Test: dm_test_operations
|
||||||
|
|
|
@ -130,6 +130,27 @@ int gpio_request(unsigned gpio, const char *label)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gpio_requestf() - [COMPAT] Request GPIO
|
||||||
|
* @gpio: GPIO number
|
||||||
|
* @fmt: Format string for the requested GPIO
|
||||||
|
* @...: Arguments for the printf() format string
|
||||||
|
*
|
||||||
|
* This function implements the API that's compatible with current
|
||||||
|
* GPIO API used in U-Boot. The request is forwarded to particular
|
||||||
|
* GPIO driver. Returns 0 on success, negative value on error.
|
||||||
|
*/
|
||||||
|
int gpio_requestf(unsigned gpio, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
char buf[40];
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
vscnprintf(buf, sizeof(buf), fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return gpio_request(gpio, buf);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gpio_free() - [COMPAT] Relinquish GPIO
|
* gpio_free() - [COMPAT] Relinquish GPIO
|
||||||
* gpio: GPIO number
|
* gpio: GPIO number
|
||||||
|
|
|
@ -145,6 +145,16 @@ int gpio_get_function(struct udevice *dev, int offset, const char **namep);
|
||||||
*/
|
*/
|
||||||
int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep);
|
int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gpio_requestf() - request a GPIO using a format string for the owner
|
||||||
|
*
|
||||||
|
* This is a helper function for gpio_request(). It allows you to provide
|
||||||
|
* a printf()-format string for the GPIO owner. It calls gpio_request() with
|
||||||
|
* the string that is created
|
||||||
|
*/
|
||||||
|
int gpio_requestf(unsigned gpio, const char *fmt, ...)
|
||||||
|
__attribute__ ((format (__printf__, 2, 3)));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct struct dm_gpio_ops - Driver model GPIO operations
|
* struct struct dm_gpio_ops - Driver model GPIO operations
|
||||||
*
|
*
|
||||||
|
|
|
@ -120,3 +120,21 @@ static int dm_test_gpio_anon(struct dm_test_state *dms)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DM_TEST(dm_test_gpio_anon, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
DM_TEST(dm_test_gpio_anon, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
||||||
|
|
||||||
|
/* Test that gpio_requestf() works as expected */
|
||||||
|
static int dm_test_gpio_requestf(struct dm_test_state *dms)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_gpio_requestf, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
||||||
|
|
Loading…
Add table
Reference in a new issue