summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/aigo/usb-erosq.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/aigo/usb-erosq.c')
-rw-r--r--firmware/target/hosted/aigo/usb-erosq.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/firmware/target/hosted/aigo/usb-erosq.c b/firmware/target/hosted/aigo/usb-erosq.c
new file mode 100644
index 0000000000..2a3acf4d62
--- /dev/null
+++ b/firmware/target/hosted/aigo/usb-erosq.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#include "power-erosq.h"
30
31static bool adb_mode = false;
32
33/* TODO: implement usb detection properly */
34int usb_detect(void)
35{
36 return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED;
37}
38
39void usb_enable(bool on)
40{
41 /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell
42 * without entering ums mode
43 */
44 if (!adb_mode)
45 {
46 sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0);
47 }
48}
49
50/* This is called by usb thread after usb extract in order to return
51 * regular FS access
52 *
53 * returns the # of successful mounts
54*/
55int disk_mount_all(void)
56{
57 const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"};
58 const char *fs[] = {"vfat", "exfat"};
59
60 sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "");
61
62 for (int i=0; i<2; i++)
63 {
64 for (int j=0; j<2; j++)
65 {
66 if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0)
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 */
80int 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
91void 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", "0023");
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", "ErosQ 0100");
118}