]> Git Repo - J-u-boot.git/blame - cmd/rockusb.c
Merge patch series "Cumulative fixes and updates for MediaTek ethernet driver"
[J-u-boot.git] / cmd / rockusb.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
453c95e0
EC
2/*
3 * Copyright (C) 2017 Eddie Cai <[email protected]>
453c95e0
EC
4 */
5
453c95e0
EC
6#include <command.h>
7#include <console.h>
8#include <g_dnl.h>
9#include <usb.h>
15f09a1a 10#include <asm/arch-rockchip/f_rockusb.h>
453c95e0 11
09140113
SG
12static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
13 char *const argv[])
453c95e0
EC
14{
15 int controller_index, dev_index;
16 char *usb_controller;
0669a929 17 struct udevice *udc;
453c95e0
EC
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
0669a929 37 ret = udc_device_get_by_index(controller_index, &udc);
453c95e0
EC
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;
0669a929 59 dm_usb_gadget_handle_interrupts(udc);
453c95e0
EC
60 }
61 ret = CMD_RET_SUCCESS;
62
63exit:
64 g_dnl_unregister();
65 g_dnl_clear_detach();
0669a929 66 udc_device_put(udc);
453c95e0
EC
67
68 return ret;
69}
70
71U_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);
This page took 0.19404 seconds and 4 git commands to generate.