summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sparmann <theseven@gmx.net>2014-07-19 18:32:55 +0200
committerCástor Muñoz <cmvidal@gmail.com>2016-02-14 15:42:54 +0100
commitbc56811a0e1df3e7902b85cf2250d970e0a929d5 (patch)
tree068be6ee573842517af522c78323739fc28cfd4f
parent929be521d4dd8a0ed3b3a42cd22e1659407ce83a (diff)
iPod Nano 2G and Classic: Fix power and charging detection.
This should allow FireWire charging to work on these devices. It also adds charging state detection on the iPod Classic. (cherry picked from commit fa86fec4fb089b47f5c2c3b1f2f3dbc97551895b) On Classic (and probably Nano 2G), it seems that the 100/500mA limit applies only to USB chargers, when FW is connected it supplies all the power (even if USB is also connected) and USB current limit does not affect to FW charging, therefore the limit is only set when USB is connected. Change-Id: I7c6bab1b6a0f295367999c45faeda6085c3fb091 Signed-off-by: Cástor Muñoz <cmvidal@gmail.com>
-rw-r--r--firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c14
-rw-r--r--firmware/target/arm/s5l8700/usb-nano2g-6g.c2
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c14
3 files changed, 25 insertions, 5 deletions
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c
index 10d96fd59c..989fb1550b 100644
--- a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c
+++ b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c
@@ -61,11 +61,21 @@ void usb_charging_maxcurrent_change(int maxcurrent)
unsigned int power_input_status(void)
{
- return (PDAT14 & 8) ? POWER_INPUT_NONE : POWER_INPUT_MAIN_CHARGER;
+ /* This checks if USB Vbus is present. */
+ if (!(PDAT14 & 0x8)) return POWER_INPUT_USB_CHARGER;
+
+ /* If USB Vbus is not present, check if we have a positive power balance
+ regardless. This would indicate FireWire charging. Note that this will
+ drop to POWER_INPUT_NONE if FireWire isn't able to supply enough current
+ for device operation, e.g. during disk spinup. */
+ if (PDAT11 & 0x20) return POWER_INPUT_NONE;
+
+ /* Looks like we have FireWire power. */
+ return POWER_INPUT_MAIN_CHARGER;
}
bool charging_state(void)
{
- return (PDAT11 & 0x10) ? false : true;
+ return (PDAT11 & 0x10) ? 0 : 1;
}
#endif /* CONFIG_CHARGING */
diff --git a/firmware/target/arm/s5l8700/usb-nano2g-6g.c b/firmware/target/arm/s5l8700/usb-nano2g-6g.c
index 1807a39c76..db397f8fd5 100644
--- a/firmware/target/arm/s5l8700/usb-nano2g-6g.c
+++ b/firmware/target/arm/s5l8700/usb-nano2g-6g.c
@@ -37,7 +37,7 @@ void usb_enable(bool on)
int usb_detect(void)
{
- if (charger_inserted())
+ if (power_input_status() & POWER_INPUT_USB)
return USB_INSERTED;
return USB_EXTRACTED;
}
diff --git a/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
index 64e9457430..57358b8cb6 100644
--- a/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
@@ -117,11 +117,21 @@ void usb_charging_maxcurrent_change(int maxcurrent)
unsigned int power_input_status(void)
{
- return (PDAT(12) & 8) ? POWER_INPUT_NONE : POWER_INPUT_MAIN_CHARGER;
+ /* This checks if USB Vbus is present. */
+ if (!(PDAT(12) & 0x8)) return POWER_INPUT_USB_CHARGER;
+
+ /* If USB Vbus is not present, check if we have a positive power balance
+ regardless. This would indicate FireWire charging. Note that this will
+ drop to POWER_INPUT_NONE if FireWire isn't able to supply enough current
+ for device operation, e.g. during disk spinup. */
+ if (PDAT(11) & 0x20) return POWER_INPUT_NONE;
+
+ /* Looks like we have FireWire power. */
+ return POWER_INPUT_MAIN_CHARGER;
}
bool charging_state(void)
{
- return false; //TODO: Figure out
+ return (PDAT(11) & 0x10) ? 0 : 1;
}
#endif /* CONFIG_CHARGING */