diff options
author | Simon Glass <sjg@chromium.org> | 2015-01-05 20:05:31 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2015-01-29 17:09:51 -0700 |
commit | a02af4aeece40e93bc7d79cd5dc912409efb7020 (patch) | |
tree | 799cf6f844e86be0164e4cc1649b62d1c9911eb5 /common/cmd_demo.c | |
parent | 5d1c17e9a5803af9c65966e469437735ac29659e (diff) | |
download | u-boot-imx-a02af4aeece40e93bc7d79cd5dc912409efb7020.zip u-boot-imx-a02af4aeece40e93bc7d79cd5dc912409efb7020.tar.gz u-boot-imx-a02af4aeece40e93bc7d79cd5dc912409efb7020.tar.bz2 |
dm: demo: Add a simple GPIO demonstration
Add a new 'demo light' command which uses GPIOs to control imaginary lights.
Each light is assigned a bit number in the overall value. This provides an
example driver for using the new GPIO API.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/cmd_demo.c')
-rw-r--r-- | common/cmd_demo.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/common/cmd_demo.c b/common/cmd_demo.c index 652c61c..bcb34d9 100644 --- a/common/cmd_demo.c +++ b/common/cmd_demo.c @@ -39,6 +39,26 @@ static int do_demo_status(cmd_tbl_t *cmdtp, int flag, int argc, return 0; } +static int do_demo_light(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + int light; + int ret; + + if (argc) { + light = simple_strtoul(argv[0], NULL, 16); + ret = demo_set_light(demo_dev, light); + } else { + ret = demo_get_light(demo_dev); + if (ret >= 0) { + printf("Light: %x\n", ret); + ret = 0; + } + } + + return ret; +} + int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct udevice *dev; @@ -61,6 +81,7 @@ int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) static cmd_tbl_t demo_commands[] = { U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""), U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""), + U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""), U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""), }; @@ -86,6 +107,10 @@ static int do_demo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return cmd_process_error(cmdtp, ret); argc--; argv++; + } else { + demo_dev = NULL; + if (demo_cmd->cmd != do_demo_list) + return CMD_RET_USAGE; } ret = demo_cmd->cmd(demo_cmd, flag, argc, argv); @@ -98,5 +123,7 @@ U_BOOT_CMD( "Driver model (dm) demo operations", "list List available demo devices\n" "demo hello <num> [<char>] Say hello\n" - "demo status <num> Get demo device status" + "demo light [<num>] Set or get the lights\n" + "demo status <num> Get demo device status\n" + "demo list List available demo devices" ); |