diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-10-15 10:18:16 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-10-15 10:18:16 -0400 |
commit | d544ce46a78c834492ae1116cd1d1e47cb9d8cb0 (patch) | |
tree | 8b17557587863e497f7aee421efe86192ec0ea4e /firmware/target/hosted/usb-hiby.c | |
parent | 4873a1ac6177cf7319160d4fa290fe2b17615763 (diff) | |
download | rockbox-d544ce46a78c834492ae1116cd1d1e47cb9d8cb0.tar.gz rockbox-d544ce46a78c834492ae1116cd1d1e47cb9d8cb0.zip |
hosted: Unify the USB code for the hiby-based players.
* Specify exported USB VID/PID in target config header
* Don't fail if the sd filesystem has already been remounted
(ie due to platform hotplug)
Change-Id: Ifd2dae0c4f15086bf2bf89eb093018b3c4d2b75d
Diffstat (limited to 'firmware/target/hosted/usb-hiby.c')
-rw-r--r-- | firmware/target/hosted/usb-hiby.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/firmware/target/hosted/usb-hiby.c b/firmware/target/hosted/usb-hiby.c new file mode 100644 index 0000000000..6c35e76e29 --- /dev/null +++ b/firmware/target/hosted/usb-hiby.c | |||
@@ -0,0 +1,118 @@ | |||
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 | |||
30 | static bool adb_mode = false; | ||
31 | |||
32 | /* TODO: implement usb detection properly */ | ||
33 | int usb_detect(void) | ||
34 | { | ||
35 | return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED; | ||
36 | } | ||
37 | |||
38 | void usb_enable(bool on) | ||
39 | { | ||
40 | /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell | ||
41 | * without entering ums mode | ||
42 | */ | ||
43 | if (!adb_mode) | ||
44 | { | ||
45 | sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | /* This is called by usb thread after usb extract in order to return | ||
50 | * regular FS access | ||
51 | * | ||
52 | * returns the # of successful mounts | ||
53 | */ | ||
54 | int disk_mount_all(void) | ||
55 | { | ||
56 | const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"}; | ||
57 | const char *fs[] = {"vfat", "exfat"}; | ||
58 | |||
59 | sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", ""); | ||
60 | |||
61 | for (int i=0; i<2; i++) | ||
62 | { | ||
63 | for (int j=0; j<2; j++) | ||
64 | { | ||
65 | int rval = mount(dev[i], PIVOT_ROOT, fs[j], 0, NULL); | ||
66 | if (rval == 0 || errno == -EBUSY) | ||
67 | { | ||
68 | return 1; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | /* This is called by usb thread after all threads ACKs usb inserted message | ||
77 | * | ||
78 | * returns the # of successful unmounts | ||
79 | */ | ||
80 | int disk_unmount_all(void) | ||
81 | { | ||
82 | if (umount("/mnt/sd_0") == 0) | ||
83 | { | ||
84 | sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0"); | ||
85 | return 1; | ||
86 | } | ||
87 | |||
88 | return 0; | ||
89 | } | ||
90 | |||
91 | void usb_init_device(void) | ||
92 | { | ||
93 | char functions[32] = {0}; | ||
94 | |||
95 | /* Check if ADB was activated in bootloader */ | ||
96 | sysfs_get_string("/sys/class/android_usb/android0/functions", functions, sizeof(functions)); | ||
97 | adb_mode = (strstr(functions, "adb") == NULL) ? false : true; | ||
98 | |||
99 | usb_enable(false); | ||
100 | |||
101 | if (adb_mode) | ||
102 | { | ||
103 | sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage,adb"); | ||
104 | sysfs_set_string("/sys/class/android_usb/android0/idVendor", "18D1"); | ||
105 | sysfs_set_string("/sys/class/android_usb/android0/idProduct", "D002"); | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage"); | ||
110 | sysfs_set_string("/sys/class/android_usb/android0/idVendor", "C502"); | ||
111 | sysfs_set_string("/sys/class/android_usb/android0/idProduct", "0029"); | ||
112 | } | ||
113 | |||
114 | sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org"); | ||
115 | sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player"); | ||
116 | sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF"); | ||
117 | sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "Rockbox 0100"); | ||
118 | } | ||