summaryrefslogtreecommitdiffstats
path: root/utils/ypr0tools/cable_detect.c
diff options
context:
space:
mode:
authorLorenzo Miori <memorys60@gmail.com>2013-07-23 16:24:19 +0200
committerThomas Martitz <kugel@rockbox.org>2013-09-16 12:55:48 +0200
commit66aa00d3e051956b634ea157c71782add41d7ed1 (patch)
tree4c992994bbae116dae8ac90a08710fe84e4f4694 /utils/ypr0tools/cable_detect.c
parent5ef1e2dcfa2845d7196223af2e170798f7621df6 (diff)
downloadrockbox-66aa00d3e051956b634ea157c71782add41d7ed1.tar.gz
rockbox-66aa00d3e051956b634ea157c71782add41d7ed1.zip
Samsung YP-R0/YP-R1 Safe Mode improvement
This is an improvement for the special mode present in the samsung ypr0 target. Apart adding new useful functionalities, it fixes a random disconnection bug, solved by debouncing and fully support to YP-R1 target. This opens also the possibility to interface this operating mode to rockbox USB functionality. Change-Id: Id70541541fcfaa1234328485fab0696a3bd491c9
Diffstat (limited to 'utils/ypr0tools/cable_detect.c')
-rw-r--r--utils/ypr0tools/cable_detect.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/utils/ypr0tools/cable_detect.c b/utils/ypr0tools/cable_detect.c
new file mode 100644
index 0000000000..57679d4b79
--- /dev/null
+++ b/utils/ypr0tools/cable_detect.c
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Samsung YP-R1 runtime USB cable detection
+ *
+ * Copyright (C) 2013 Lorenzo Miori
+ *
+ * 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 <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#define IOCTL_PMU_MAGIC 'A'
+
+#define E_IOCTL_PMU_GET_BATT_LVL 0
+#define E_IOCTL_PMU_GET_CHG_STATUS 1
+#define E_IOCTL_PMU_IS_EXT_PWR 2
+#define E_IOCTL_PMU_STOP_CHG 3
+#define E_IOCTL_PMU_START_CHG 4
+#define E_IOCTL_PMU_IS_EXT_PWR_OVP 5
+#define E_IOCTL_PMU_LCD_DIM_CTRL 6
+#define E_IOCTL_PMU_CORE_CTL_HIGH 7
+#define E_IOCTL_PMU_CORE_CTL_LOW 8
+#define E_IOCTL_PMU_TSP_USB_PWR_OFF 9
+
+#define IOCTL_PMU_GET_BATT_LVL _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_GET_BATT_LVL)
+#define IOCTL_PMU_GET_CHG_STATUS _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_GET_CHG_STATUS)
+#define IOCTL_PMU_IS_EXT_PWR _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_IS_EXT_PWR)
+#define IOCTL_PMU_STOP_CHG _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_STOP_CHG)
+#define IOCTL_PMU_START_CHG _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_START_CHG)
+#define IOCTL_PMU_IS_EXT_PWR_OVP _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_IS_EXT_PWR_OVP)
+#define IOCTL_PMU_LCD_DIM_CTRL _IOW(IOCTL_PMU_MAGIC, E_IOCTL_PMU_LCD_DIM_CTRL, int)
+#define IOCTL_PMU_CORE_CTL_HIGH _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_CORE_CTL_HIGH)
+#define IOCTL_PMU_CORE_CTL_LOW _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_CORE_CTL_LOW)
+#define IOCTL_PMU_TSP_USB_PWR_OFF _IO(IOCTL_PMU_MAGIC, E_IOCTL_PMU_TSP_USB_PWR_OFF)
+
+/*
+ * This is a very simple program that runs on device.
+ * It returns error code either 0 when (power/usb) cable
+ * is not connected or >= 1 if connected.
+ */
+int main(void)
+{
+ int state = -1;
+ int dev = open("/dev/r1Pmu", O_RDONLY);
+ state = ioctl(dev, IOCTL_PMU_IS_EXT_PWR);
+ close(dev);
+ return state;
+}