Commit b9dfcf4133c632627cb215b572bcba5c60e21d24

Authored by Aurelien Jacquiot
Committed by Lokesh Vutla
1 parent 16b660aff2

cmd: rapidio: add rapidio command group

This patch adds a new group of 'rio' commands that allows to
initialize and perform basic RapidIO operations needed for
supporting the RapidIO boot feature.

Signed-off-by: Aurelien Jacquiot <a-jacquiot@ti.com>
Signed-off-by: WingMan Kwok <w-kwok2@ti.com>

Showing 3 changed files with 223 additions and 0 deletions Side-by-side Diff

... ... @@ -459,6 +459,12 @@
459 459 help
460 460 GPIO support.
461 461  
  462 +config CMD_RIO
  463 + bool "rapidio"
  464 + select DM_RIO
  465 + help
  466 + RapidIO support.
  467 +
462 468 endmenu
463 469  
464 470  
... ... @@ -153,6 +153,7 @@
153 153 obj-$(CONFIG_CMD_DFU) += dfu.o
154 154 obj-$(CONFIG_CMD_GPT) += gpt.o
155 155 obj-$(CONFIG_CMD_ETHSW) += ethsw.o
  156 +obj-$(CONFIG_CMD_RIO) += rio.o
156 157  
157 158 # Power
158 159 obj-$(CONFIG_CMD_PMIC) += pmic.o
  1 +/*
  2 + * (C) Copyright 2017
  3 + * Texas Instruments Incorporated, <www.ti.com>
  4 + * Authors: Aurelien Jacquiot <a-jacquiot@ti.com>
  5 + * WingMan Kwok <w-kwok2@ti.com>
  6 + *
  7 + * SPDX-License-Identifier: GPL-2.0+
  8 + */
  9 +
  10 +/*
  11 + * RapidIO support
  12 + */
  13 +#include <common.h>
  14 +#include <command.h>
  15 +#include <mapmem.h>
  16 +#include <asm/io.h>
  17 +#include <watchdog.h>
  18 +#include <rio.h>
  19 +
  20 +static struct udevice *rio_dev;
  21 +
  22 +static int do_rio_local_write(cmd_tbl_t *cmdtp, int flag, int argc,
  23 + char * const argv[])
  24 +{
  25 + u32 offset, val;
  26 + int ret;
  27 +
  28 + offset = simple_strtoul(argv[0], NULL, 16);
  29 + val = simple_strtoul(argv[1], NULL, 16);
  30 +
  31 + ret = rio_local_config_write(rio_dev, offset, sizeof(val), val);
  32 + if (ret) {
  33 + printf("cannot perform local write\n");
  34 + return CMD_RET_FAILURE;
  35 + }
  36 +
  37 + return CMD_RET_SUCCESS;
  38 +}
  39 +
  40 +static int do_rio_local_read(cmd_tbl_t *cmdtp, int flag, int argc,
  41 + char * const argv[])
  42 +{
  43 + u32 offset, val;
  44 + int ret;
  45 +
  46 + offset = simple_strtoul(argv[0], NULL, 16);
  47 +
  48 + ret = rio_local_config_read(rio_dev, offset, sizeof(val), &val);
  49 + if (ret) {
  50 + printf("cannot perform local read\n");
  51 + return CMD_RET_FAILURE;
  52 + }
  53 +
  54 + /* Display value */
  55 + print_buffer(offset, (const void *)&val, sizeof(val), 1, 0);
  56 + return CMD_RET_SUCCESS;
  57 +}
  58 +
  59 +static int do_rio_write(cmd_tbl_t *cmdtp, int flag, int argc,
  60 + char * const argv[])
  61 +{
  62 + int portid;
  63 + u16 destid;
  64 + u8 hopcount;
  65 + u32 offset;
  66 + u32 val;
  67 + int ret;
  68 +
  69 + portid = simple_strtol(argv[0], NULL, 10);
  70 + destid = simple_strtol(argv[1], NULL, 10) & 0xffff;
  71 + hopcount = simple_strtoul(argv[2], NULL, 10) & 0xff;
  72 + offset = simple_strtoul(argv[3], NULL, 16);
  73 + val = simple_strtoul(argv[4], NULL, 16);
  74 +
  75 + /* Do maintenance write */
  76 + ret = rio_config_write(rio_dev, portid, destid, hopcount,
  77 + offset, sizeof(val), val);
  78 +
  79 + if (ret) {
  80 + printf("cannot perform maintenance write\n");
  81 + return CMD_RET_FAILURE;
  82 + }
  83 +
  84 + return CMD_RET_SUCCESS;
  85 +}
  86 +
  87 +static int do_rio_read(cmd_tbl_t *cmdtp, int flag, int argc,
  88 + char * const argv[])
  89 +{
  90 + int portid;
  91 + u16 destid;
  92 + u8 hopcount;
  93 + u32 offset;
  94 + u32 val;
  95 + int ret;
  96 +
  97 + portid = simple_strtol(argv[0], NULL, 10);
  98 + destid = simple_strtol(argv[1], NULL, 10) & 0xffff;
  99 + hopcount = simple_strtoul(argv[2], NULL, 10) & 0xff;
  100 + offset = simple_strtoul(argv[3], NULL, 16);
  101 +
  102 + /* Do maintenance read */
  103 + ret = rio_config_read(rio_dev, portid, destid, hopcount,
  104 + offset, sizeof(val), &val);
  105 +
  106 + if (ret) {
  107 + printf("cannot perform maintenance read\n");
  108 + return CMD_RET_FAILURE;
  109 + }
  110 +
  111 + /* Display value */
  112 + print_buffer(offset, (const void *)&val, sizeof(val), 1, 0);
  113 + return CMD_RET_SUCCESS;
  114 +}
  115 +
  116 +static int do_rio_doorbell_rx(cmd_tbl_t *cmdtp, int flag, int argc,
  117 + char * const argv[])
  118 +{
  119 + u32 info = 0;
  120 + int ret;
  121 +
  122 + if (!argc)
  123 + return CMD_RET_USAGE;
  124 +
  125 + info = simple_strtoul(argv[0], NULL, 16);
  126 +
  127 + ret = rio_doorbell_rx(rio_dev, info);
  128 + if (!ret)
  129 + return CMD_RET_SUCCESS;
  130 +
  131 + return CMD_RET_FAILURE;
  132 +}
  133 +
  134 +static int do_rio_remove(cmd_tbl_t *cmdtp, int flag, int argc,
  135 + char * const argv[])
  136 +{
  137 + rio_remove(rio_dev);
  138 + rio_dev = NULL;
  139 + return CMD_RET_SUCCESS;
  140 +}
  141 +
  142 +static int do_rio_devices(cmd_tbl_t *cmdtp, int flag,
  143 + int argc, char * const argv[])
  144 +{
  145 + struct udevice *dev;
  146 + int i, ret;
  147 +
  148 + puts("RapidIO uclass entries:\n");
  149 + printf("devnum device driver\n");
  150 +
  151 + for (i = 0, ret = uclass_first_device(UCLASS_RIO, &dev);
  152 + dev;
  153 + ret = uclass_next_device(&dev)) {
  154 + printf(" %d %s %s\n",
  155 + i++, dev->name, dev->driver->name);
  156 + }
  157 +
  158 + return cmd_process_error(cmdtp, ret);
  159 +}
  160 +
  161 +static cmd_tbl_t rio_commands[] = {
  162 + U_BOOT_CMD_MKENT(devices, 0, 1, do_rio_devices, "", ""),
  163 + U_BOOT_CMD_MKENT(remove, 1, 0, do_rio_remove, "", ""),
  164 + U_BOOT_CMD_MKENT(doorbell_rx, 2, 0, do_rio_doorbell_rx, "", ""),
  165 + U_BOOT_CMD_MKENT(r, 5, 1, do_rio_read, "", ""),
  166 + U_BOOT_CMD_MKENT(w, 6, 0, do_rio_write, "", ""),
  167 + U_BOOT_CMD_MKENT(lr, 2, 1, do_rio_local_read, "", ""),
  168 + U_BOOT_CMD_MKENT(lw, 3, 0, do_rio_local_write, "", ""),
  169 +};
  170 +
  171 +static int do_rio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  172 +{
  173 + cmd_tbl_t *rio_cmd;
  174 + int devnum = 0;
  175 + int ret;
  176 +
  177 + if (argc < 2)
  178 + return CMD_RET_USAGE;
  179 +
  180 + rio_cmd = find_cmd_tbl(argv[1], rio_commands,
  181 + ARRAY_SIZE(rio_commands));
  182 + argc -= 2;
  183 + argv += 2;
  184 +
  185 + if ((!rio_cmd || argc > rio_cmd->maxargs) ||
  186 + ((strcmp(rio_cmd->name, "devices")) && (argc < 1)))
  187 + return CMD_RET_USAGE;
  188 +
  189 + if (argc) {
  190 + devnum = simple_strtoul(argv[0], NULL, 10);
  191 + ret = uclass_get_device(UCLASS_RIO, devnum, &rio_dev);
  192 + if (ret)
  193 + return cmd_process_error(cmdtp, ret);
  194 + argc--;
  195 + argv++;
  196 + } else {
  197 + rio_dev = NULL;
  198 + if (rio_cmd->cmd != do_rio_devices)
  199 + return CMD_RET_USAGE;
  200 + }
  201 +
  202 + ret = rio_cmd->cmd(rio_cmd, flag, argc, argv);
  203 +
  204 + return cmd_process_error(rio_cmd, ret);
  205 +}
  206 +
  207 +U_BOOT_CMD(rio, CONFIG_SYS_MAXARGS, 0, do_rio,
  208 + "RapidIO sub-system",
  209 + "devices - show available RapidIO devices\n"
  210 + "rio remove <devnum> - remove RapidIO device\n"
  211 + "rio doorbell_rx <devnum> [info] - blocking wait for doorbell info\n"
  212 + "rio r <devnum> port dst_id hopcount offset - perform config read\n"
  213 + "rio w <devnum> port dst_id hopcount offset value - perform config write\n"
  214 + "rio lr <devnum> offset - perform local config read\n"
  215 + "rio lw <devnum> offset value - perform local config write\n"
  216 +);