]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_usb_mass_storage.c
karo: tx6: factor out PMIC initialization
[karo-tx-uboot.git] / common / cmd_usb_mass_storage.c
1 /*
2  * Copyright (C) 2011 Samsung Electronics
3  * Lukasz Majewski <l.majewski@samsung.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <errno.h>
9 #include <common.h>
10 #include <command.h>
11 #include <g_dnl.h>
12 #include <usb_mass_storage.h>
13
14 int do_usb_mass_storage(cmd_tbl_t *cmdtp, int flag,
15                                int argc, char * const argv[])
16 {
17         char *ep;
18         unsigned int dev_num = 0, offset = 0, part_size = 0;
19         int rc;
20
21         struct ums_board_info *ums_info;
22         static char *s = "ums";
23
24         if (argc < 2) {
25                 printf("usage: ums <dev> - e.g. ums 0\n");
26                 return 0;
27         }
28
29         dev_num = (int)simple_strtoul(argv[1], &ep, 16);
30
31         if (dev_num) {
32                 puts("\nSet eMMC device to 0! - e.g. ums 0\n");
33                 goto fail;
34         }
35
36         board_usb_init();
37         ums_info = board_ums_init(dev_num, offset, part_size);
38
39         if (!ums_info) {
40                 printf("MMC: %d -> NOT available\n", dev_num);
41                 goto fail;
42         }
43         rc = fsg_init(ums_info);
44         if (rc) {
45                 printf("cmd ums: fsg_init failed\n");
46                 goto fail;
47         }
48
49         g_dnl_register(s);
50
51         while (1) {
52                 /* Handle control-c and timeouts */
53                 if (ctrlc()) {
54                         printf("The remote end did not respond in time.\n");
55                         goto exit;
56                 }
57                 usb_gadget_handle_interrupts();
58                 /* Check if USB cable has been detached */
59                 if (fsg_main_thread(NULL) == EIO)
60                         goto exit;
61         }
62 exit:
63         g_dnl_unregister();
64         return 0;
65
66 fail:
67         return -1;
68 }
69
70 U_BOOT_CMD(ums, CONFIG_SYS_MAXARGS, 1, do_usb_mass_storage,
71         "Use the UMS [User Mass Storage]",
72         "ums - User Mass Storage Gadget"
73 );