blob: 07088564a109b60acce67d6857a5223b6c9648a6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Eddie Cai5e3020b2017-12-15 08:17:11 +08002/*
3 * Copyright (C) 2017 Eddie Cai <eddie.cai.linux@gmail.com>
Eddie Cai5e3020b2017-12-15 08:17:11 +08004 */
5
6#include <common.h>
7#include <command.h>
8#include <console.h>
9#include <g_dnl.h>
10#include <usb.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080011#include <asm/arch-rockchip/f_rockusb.h>
Eddie Cai5e3020b2017-12-15 08:17:11 +080012
Simon Glassed38aef2020-05-10 11:40:03 -060013static int do_rockusb(struct cmd_tbl *cmdtp, int flag, int argc,
14 char *const argv[])
Eddie Cai5e3020b2017-12-15 08:17:11 +080015{
16 int controller_index, dev_index;
17 char *usb_controller;
Marek Vasutfdf2ed72023-09-01 11:49:51 +020018 struct udevice *udc;
Eddie Cai5e3020b2017-12-15 08:17:11 +080019 char *devtype;
20 char *devnum;
21 int ret;
22
23 if (argc < 2)
24 return CMD_RET_USAGE;
25
26 usb_controller = argv[1];
27 controller_index = simple_strtoul(usb_controller, NULL, 0);
28
29 if (argc >= 4) {
30 devtype = argv[2];
31 devnum = argv[3];
32 } else {
33 return CMD_RET_USAGE;
34 }
35 dev_index = simple_strtoul(devnum, NULL, 0);
36 rockusb_dev_init(devtype, dev_index);
37
Marek Vasutfdf2ed72023-09-01 11:49:51 +020038 ret = udc_device_get_by_index(controller_index, &udc);
Eddie Cai5e3020b2017-12-15 08:17:11 +080039 if (ret) {
40 printf("USB init failed: %d\n", ret);
41 return CMD_RET_FAILURE;
42 }
43
44 g_dnl_clear_detach();
45 ret = g_dnl_register("usb_dnl_rockusb");
46 if (ret)
47 return CMD_RET_FAILURE;
48
49 if (!g_dnl_board_usb_cable_connected()) {
50 puts("\rUSB cable not detected, Command exit.\n");
51 ret = CMD_RET_FAILURE;
52 goto exit;
53 }
54
55 while (1) {
56 if (g_dnl_detach())
57 break;
58 if (ctrlc())
59 break;
Marek Vasutfdf2ed72023-09-01 11:49:51 +020060 dm_usb_gadget_handle_interrupts(udc);
Eddie Cai5e3020b2017-12-15 08:17:11 +080061 }
62 ret = CMD_RET_SUCCESS;
63
64exit:
65 g_dnl_unregister();
66 g_dnl_clear_detach();
Marek Vasutfdf2ed72023-09-01 11:49:51 +020067 udc_device_put(udc);
Eddie Cai5e3020b2017-12-15 08:17:11 +080068
69 return ret;
70}
71
72U_BOOT_CMD(rockusb, 4, 1, do_rockusb,
73 "use the rockusb protocol",
74 "<USB_controller> <devtype> <dev[:part]> e.g. rockusb 0 mmc 0\n"
75);