2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-02-26 22:59:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Google, Inc
|
|
|
|
*
|
|
|
|
* (C) Copyright 2012
|
|
|
|
* Pavel Herrmann <morpheus.ibis@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2020-07-19 16:15:36 +00:00
|
|
|
#include <dm.h>
|
2014-02-26 22:59:23 +00:00
|
|
|
#include <dm-demo.h>
|
2015-03-22 22:08:59 +00:00
|
|
|
#include <mapmem.h>
|
2014-02-26 22:59:23 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *demo_dev;
|
2014-02-26 22:59:23 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_demo_hello(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2014-02-26 22:59:23 +00:00
|
|
|
{
|
|
|
|
int ch = 0;
|
|
|
|
|
|
|
|
if (argc)
|
|
|
|
ch = *argv[0];
|
|
|
|
|
|
|
|
return demo_hello(demo_dev, ch);
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_demo_status(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2014-02-26 22:59:23 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = demo_status(demo_dev, &status);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
printf("Status: %d\n", status);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_demo_light(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2015-01-06 03:05:31 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
int do_demo_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
2014-02-26 22:59:23 +00:00
|
|
|
{
|
2014-05-22 10:43:05 +00:00
|
|
|
struct udevice *dev;
|
2014-02-26 22:59:23 +00:00
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
puts("Demo uclass entries:\n");
|
|
|
|
|
|
|
|
for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev);
|
|
|
|
dev;
|
|
|
|
ret = uclass_next_device(&dev)) {
|
|
|
|
printf("entry %d - instance %08x, ops %08x, platdata %08x\n",
|
2018-02-12 07:05:57 +00:00
|
|
|
i++, (uint)map_to_sysmem(dev),
|
|
|
|
(uint)map_to_sysmem(dev->driver->ops),
|
|
|
|
(uint)map_to_sysmem(dev_get_platdata(dev)));
|
2014-02-26 22:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cmd_process_error(cmdtp, ret);
|
|
|
|
}
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static struct cmd_tbl demo_commands[] = {
|
2014-02-26 22:59:23 +00:00
|
|
|
U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
|
|
|
|
U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
|
2015-01-06 03:05:31 +00:00
|
|
|
U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""),
|
2014-02-26 22:59:23 +00:00
|
|
|
U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
|
|
|
|
};
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_demo(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
2014-02-26 22:59:23 +00:00
|
|
|
{
|
2020-05-10 17:40:03 +00:00
|
|
|
struct cmd_tbl *demo_cmd;
|
2014-02-26 22:59:23 +00:00
|
|
|
int devnum = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
demo_cmd = find_cmd_tbl(argv[1], demo_commands,
|
|
|
|
ARRAY_SIZE(demo_commands));
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
2015-02-03 19:18:49 +00:00
|
|
|
|
|
|
|
if ((!demo_cmd || argc > demo_cmd->maxargs) ||
|
|
|
|
((demo_cmd->name[0] != 'l') && (argc < 1)))
|
2014-02-26 22:59:23 +00:00
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
if (argc) {
|
|
|
|
devnum = simple_strtoul(argv[0], NULL, 10);
|
|
|
|
ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
|
|
|
|
if (ret)
|
|
|
|
return cmd_process_error(cmdtp, ret);
|
|
|
|
argc--;
|
|
|
|
argv++;
|
2015-01-06 03:05:31 +00:00
|
|
|
} else {
|
|
|
|
demo_dev = NULL;
|
|
|
|
if (demo_cmd->cmd != do_demo_list)
|
|
|
|
return CMD_RET_USAGE;
|
2014-02-26 22:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
|
|
|
|
|
|
|
|
return cmd_process_error(demo_cmd, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
demo, 4, 1, do_demo,
|
|
|
|
"Driver model (dm) demo operations",
|
|
|
|
"list List available demo devices\n"
|
|
|
|
"demo hello <num> [<char>] Say hello\n"
|
2015-01-06 03:05:31 +00:00
|
|
|
"demo light [<num>] Set or get the lights\n"
|
|
|
|
"demo status <num> Get demo device status\n"
|
2014-02-26 22:59:23 +00:00
|
|
|
);
|