Commit 453c95e01a56c9eb5ac10004e9e5500bfcfa074f

Authored by Eddie Cai
Committed by Marek Vasut
1 parent bf2b72bef1

usb: rockchip: add rockusb command

this patch add rockusb command. the usage is
rockusb <USB_controller> <devtype> <dev[:part]>
e.g. rockusb 0 mmc 0

Signed-off-by: Eddie Cai <eddie.cai.linux@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 4 changed files with 84 additions and 0 deletions Side-by-side Diff

... ... @@ -492,6 +492,7 @@
492 492 M: Eddie Cai <eddie.cai.linux@gmail.com>
493 493 S: Maintained
494 494 F: drivers/usb/gadget/f_rockusb.c
  495 +F: cmd/rockusb.c
495 496  
496 497 VIDEO
497 498 M: Anatolij Gustschin <agust@denx.de>
... ... @@ -914,6 +914,14 @@
914 914 help
915 915 Enables the command "sdp" which is used to have U-Boot emulating the
916 916 Serial Download Protocol (SDP) via USB.
  917 +config CMD_ROCKUSB
  918 + bool "rockusb"
  919 + depends on USB_FUNCTION_ROCKUSB
  920 + help
  921 + Rockusb protocol is widely used by Rockchip SoC based devices. It can
  922 + read/write info, image to/from devices. This enable rockusb command
  923 + support to communication with rockusb device. for more detail about
  924 + this command, please read doc/README.rockusb.
917 925  
918 926 config CMD_USB_MASS_STORAGE
919 927 bool "UMS usb mass storage"
... ... @@ -105,6 +105,7 @@
105 105 obj-$(CONFIG_CMD_REGINFO) += reginfo.o
106 106 obj-$(CONFIG_CMD_REISER) += reiser.o
107 107 obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o
  108 +obj-$(CONFIG_CMD_ROCKUSB) += rockusb.o
108 109 obj-$(CONFIG_SANDBOX) += host.o
109 110 obj-$(CONFIG_CMD_SATA) += sata.o
110 111 obj-$(CONFIG_CMD_NVME) += nvme.o
  1 +/*
  2 + * Copyright (C) 2017 Eddie Cai <eddie.cai.linux@gmail.com>
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <common.h>
  8 +#include <command.h>
  9 +#include <console.h>
  10 +#include <g_dnl.h>
  11 +#include <usb.h>
  12 +#include <asm/arch/f_rockusb.h>
  13 +
  14 +static int do_rockusb(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  15 +{
  16 + int controller_index, dev_index;
  17 + char *usb_controller;
  18 + char *devtype;
  19 + char *devnum;
  20 + int ret;
  21 +
  22 + if (argc < 2)
  23 + return CMD_RET_USAGE;
  24 +
  25 + usb_controller = argv[1];
  26 + controller_index = simple_strtoul(usb_controller, NULL, 0);
  27 +
  28 + if (argc >= 4) {
  29 + devtype = argv[2];
  30 + devnum = argv[3];
  31 + } else {
  32 + return CMD_RET_USAGE;
  33 + }
  34 + dev_index = simple_strtoul(devnum, NULL, 0);
  35 + rockusb_dev_init(devtype, dev_index);
  36 +
  37 + ret = board_usb_init(controller_index, USB_INIT_DEVICE);
  38 + if (ret) {
  39 + printf("USB init failed: %d\n", ret);
  40 + return CMD_RET_FAILURE;
  41 + }
  42 +
  43 + g_dnl_clear_detach();
  44 + ret = g_dnl_register("usb_dnl_rockusb");
  45 + if (ret)
  46 + return CMD_RET_FAILURE;
  47 +
  48 + if (!g_dnl_board_usb_cable_connected()) {
  49 + puts("\rUSB cable not detected, Command exit.\n");
  50 + ret = CMD_RET_FAILURE;
  51 + goto exit;
  52 + }
  53 +
  54 + while (1) {
  55 + if (g_dnl_detach())
  56 + break;
  57 + if (ctrlc())
  58 + break;
  59 + usb_gadget_handle_interrupts(controller_index);
  60 + }
  61 + ret = CMD_RET_SUCCESS;
  62 +
  63 +exit:
  64 + g_dnl_unregister();
  65 + g_dnl_clear_detach();
  66 + board_usb_cleanup(controller_index, USB_INIT_DEVICE);
  67 +
  68 + return ret;
  69 +}
  70 +
  71 +U_BOOT_CMD(rockusb, 4, 1, do_rockusb,
  72 + "use the rockusb protocol",
  73 + "<USB_controller> <devtype> <dev[:part]> e.g. rockusb 0 mmc 0\n"
  74 +);