summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2018-03-13 21:24:56 +0100
committerMarcin Bukat <marcin.bukat@gmail.com>2018-06-12 10:31:15 +0200
commit7692558674be24dfe51d7be84b4d01995c23e67b (patch)
tree9cf8909c361ea6373ee81d46518cc168c5d60074 /firmware
parentd5889b3d94c0ff2403c2c6c9c89500b85e050bca (diff)
downloadrockbox-7692558674be24dfe51d7be84b4d01995c23e67b.tar.gz
rockbox-7692558674be24dfe51d7be84b4d01995c23e67b.zip
Agptek Rocker: Implement USB mass storage driver
Agptek uses composite android driver. Change-Id: Iece188ad640f3dfd24c171946c14da4c3516b6d5
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/export/config/agptekrocker.h2
-rw-r--r--firmware/target/hosted/agptek/power-agptek.c22
-rw-r--r--firmware/target/hosted/agptek/power-agptek.h3
-rw-r--r--firmware/target/hosted/agptek/powermgmt-agptek.c4
-rw-r--r--firmware/target/hosted/agptek/usb-agptek.c118
6 files changed, 137 insertions, 13 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index b85111af44..fdfa811804 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -124,6 +124,7 @@ target/hosted/agptek/lcd-agptek.c
target/hosted/agptek/power-agptek.c
target/hosted/agptek/powermgmt-agptek.c
target/hosted/agptek/system-agptek.c
+target/hosted/agptek/usb-agptek.c
#endif
#if defined(SAMSUNG_YPR0) && !defined(SIMULATOR)
diff --git a/firmware/export/config/agptekrocker.h b/firmware/export/config/agptekrocker.h
index 517448b86d..6a0a6689b3 100644
--- a/firmware/export/config/agptekrocker.h
+++ b/firmware/export/config/agptekrocker.h
@@ -79,7 +79,7 @@
#ifndef SIMULATOR
/* We have usb power and can detect usb but it is handled by Linux */
#define HAVE_USB_POWER
-#define USB_NONE
+
#endif
#define CONFIG_BATTERY_MEASURE VOLTAGE_MEASURE
diff --git a/firmware/target/hosted/agptek/power-agptek.c b/firmware/target/hosted/agptek/power-agptek.c
index 7403801681..023d3888b9 100644
--- a/firmware/target/hosted/agptek/power-agptek.c
+++ b/firmware/target/hosted/agptek/power-agptek.c
@@ -35,19 +35,23 @@ const char * const sysfs_bat_voltage =
const char * const sysfs_bat_status =
"/sys/class/power_supply/battery/status";
-unsigned int agptek_power_get_status(void)
+const char * const sysfs_pow_supply =
+ "/sys/class/power_supply/usb/present";
+
+unsigned int agptek_power_input_status(void)
+{
+ int present = 0;
+ sysfs_get_int(sysfs_pow_supply, &present);
+
+ return present ? POWER_INPUT_USB_CHARGER : POWER_INPUT_NONE;
+}
+
+bool agptek_power_charging_status(void)
{
char buf[12] = {0};
sysfs_get_string(sysfs_bat_status, buf, sizeof(buf));
- if (strncmp(buf, "Charging", 8) == 0)
- {
- return POWER_INPUT_USB_CHARGER;
- }
- else
- {
- return POWER_INPUT_NONE;
- }
+ return (strncmp(buf, "Charging", 8) == 0);
}
unsigned int agptek_power_get_battery_voltage(void)
diff --git a/firmware/target/hosted/agptek/power-agptek.h b/firmware/target/hosted/agptek/power-agptek.h
index 16f32b76ad..1ae2ff43d6 100644
--- a/firmware/target/hosted/agptek/power-agptek.h
+++ b/firmware/target/hosted/agptek/power-agptek.h
@@ -23,7 +23,8 @@
#include <stdbool.h>
#include "config.h"
-unsigned int agptek_power_get_status(void);
+unsigned int agptek_power_input_status(void);
+bool agptek_power_charging_status(void);
unsigned int agptek_power_get_battery_voltage(void);
#endif /* _POWER_AGPTEK_H_ */
diff --git a/firmware/target/hosted/agptek/powermgmt-agptek.c b/firmware/target/hosted/agptek/powermgmt-agptek.c
index 3371d1e793..6bfccb4115 100644
--- a/firmware/target/hosted/agptek/powermgmt-agptek.c
+++ b/firmware/target/hosted/agptek/powermgmt-agptek.c
@@ -49,7 +49,7 @@ const unsigned short const percent_to_volt_charge[11] =
unsigned int power_input_status(void)
{
/* POWER_INPUT_USB_CHARGER, POWER_INPUT_NONE */
- return agptek_power_get_status();
+ return agptek_power_input_status();
}
int _battery_voltage(void)
@@ -59,5 +59,5 @@ int _battery_voltage(void)
bool charging_state(void)
{
- return agptek_power_get_status() == POWER_INPUT_USB_CHARGER;
+ return agptek_power_charging_status();
}
diff --git a/firmware/target/hosted/agptek/usb-agptek.c b/firmware/target/hosted/agptek/usb-agptek.c
new file mode 100644
index 0000000000..6c805edb5a
--- /dev/null
+++ b/firmware/target/hosted/agptek/usb-agptek.c
@@ -0,0 +1,118 @@
+/***************************************************************************
+ * __________ __ ___
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2018 by Marcin Bukat
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include <stdlib.h>
+#include <sys/mount.h>
+#include <string.h>
+#include "config.h"
+#include "disk.h"
+#include "usb.h"
+#include "sysfs.h"
+#include "power.h"
+#include "power-agptek.h"
+
+static bool adb_mode = false;
+
+/* TODO: implement usb detection properly */
+int usb_detect(void)
+{
+ return power_input_status() == POWER_INPUT_USB_CHARGER ? USB_INSERTED : USB_EXTRACTED;
+}
+
+void usb_enable(bool on)
+{
+ /* Ignore usb enable/disable when ADB is enabled so we can fireup adb shell
+ * without entering ums mode
+ */
+ if (!adb_mode)
+ {
+ sysfs_set_int("/sys/class/android_usb/android0/enable", on ? 1 : 0);
+ }
+}
+
+/* This is called by usb thread after usb extract in order to return
+ * regular FS access
+ *
+ * returns the # of successful mounts
+*/
+int disk_mount_all(void)
+{
+ const char *dev[] = {"/dev/mmcblk0p1", "/dev/mmcblk0"};
+ const char *fs[] = {"vfat", "exfat"};
+
+ sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "");
+
+ for (int i=0; i<2; i++)
+ {
+ for (int j=0; j<2; j++)
+ {
+ if (mount(dev[i], "/mnt/sd_0", fs[j], 0, NULL) == 0)
+ {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/* This is called by usb thread after all threads ACKs usb inserted message
+ *
+ * returns the # of successful unmounts
+ */
+int disk_unmount_all(void)
+{
+ if (umount("/mnt/sd_0") == 0)
+ {
+ sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/lun/file", "/dev/mmcblk0");
+ return 1;
+ }
+
+ return 0;
+}
+
+void usb_init_device(void)
+{
+ char functions[32] = {0};
+
+ /* Check if ADB was activated in bootloader */
+ sysfs_get_string("/sys/class/android_usb/android0/functions", functions, sizeof(functions));
+ adb_mode = (strstr(functions, "adb") == NULL) ? false : true;
+
+ usb_enable(false);
+
+ if (adb_mode)
+ {
+ sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage,adb");
+ sysfs_set_string("/sys/class/android_usb/android0/idVendor", "18D1");
+ sysfs_set_string("/sys/class/android_usb/android0/idProduct", "D002");
+ }
+ else
+ {
+ sysfs_set_string("/sys/class/android_usb/android0/functions", "mass_storage");
+ sysfs_set_string("/sys/class/android_usb/android0/idVendor", "C502");
+ sysfs_set_string("/sys/class/android_usb/android0/idProduct", "0029");
+ }
+
+ sysfs_set_string("/sys/class/android_usb/android0/iManufacturer", "Rockbox.org");
+ sysfs_set_string("/sys/class/android_usb/android0/iProduct", "Rockbox media player");
+ sysfs_set_string("/sys/class/android_usb/android0/iSerial", "0123456789ABCDEF");
+ sysfs_set_string("/sys/class/android_usb/android0/f_mass_storage/inquiry_string", "Agptek Rocker 0100");
+}