summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/fiio/usb-fiio.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/fiio/usb-fiio.c')
-rw-r--r--firmware/target/hosted/fiio/usb-fiio.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/firmware/target/hosted/fiio/usb-fiio.c b/firmware/target/hosted/fiio/usb-fiio.c
new file mode 100644
index 0000000000..76a0ec5a2b
--- /dev/null
+++ b/firmware/target/hosted/fiio/usb-fiio.c
@@ -0,0 +1,81 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2018 by Marcin Bukat
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 ****************************************************************************/
20
21#include <stdlib.h>
22#include <sys/mount.h>
23#include <string.h>
24#include "config.h"
25#include "disk.h"
26#include "usb.h"
27#include "sysfs.h"
28#include "power.h"
29#include "power-fiio.h"
30
31const char * const sysfs_usb_online =
32 "/sys/class/power_supply/usb/online";
33
34int usb_detect(void)
35{
36 int present = 0;
37 sysfs_get_int(sysfs_usb_online, &present);
38
39 return present ? USB_INSERTED : USB_EXTRACTED;
40}
41
42void usb_enable(bool on)
43{
44 if (on)
45 {
46 system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/libcomposite.ko");
47 system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/usb_f_mass_storage.ko");
48 system ("insmod /lib/modules/3.10.14/kernel/driver/usb/gadget/g_mass_storage.ko file=/dev/mmcblk0 removable=1");
49 }
50 else
51 {
52 system ("rmmod g_mass_storage");
53 system ("rmmod usb_f_mass_storage");
54 system ("rmmod libcomposite");
55 }
56}
57
58/* This is called by usb thread after usb extract in order to return
59 * regular FS access
60 *
61 * returns the # of successful mounts
62*/
63int disk_mount_all(void)
64{
65 return 1;
66}
67
68/* This is called by usb thread after all threads ACKs usb inserted message
69 *
70 * returns the # of successful unmounts
71 */
72int disk_unmount_all(void)
73{
74 return 1;
75}
76
77void usb_init_device(void)
78{
79 system ("insmod /lib/modules/3.10.14/kernel/driver/staging/dwc2/dwc2.ko");
80 usb_enable(true);
81}