Rockbox

  • Status Unconfirmed
  • Percent Complete
    0%
  • Task Type Patches
  • Category Battery/Charging
  • Assigned To No-one
  • Operating System Another
  • Severity Low
  • Priority Very Low
  • Reported Version Daily build (which?)
  • Due in Version Undecided
  • Due Date Undecided
  • Votes
  • Private
Attached to Project: Rockbox
Opened by prof_wolfff - 2012-01-08

FS#12522 - iPod Classic/6G: charger detection

External/USB adapters are not correctly detected on my Classic 80Gb, this patch detects it so car mode functionality now works, also the iPod is powered-up when USB cable is inserted.

The function power_input_status() returns USB charger when both external and USB chargers are present. It is possible to detect the external adapter when USB cable is plugged but it is necesary to poll the PMU (not IRQ safe), and i think this information is not currently used at all.


torne commented on 2012-01-09 11:49

Is this actually detecting the charger using apple's logic? (i.e. through the voltages/connectivity of D+ and D-)? Does this actually drive the USB charging logic correctly in the USB stack?

I really don't know how apple detects chargers, this patch is mainly based on how my 80Gb Classic behaves, i dont know if will work on all Classic models, i hope people will report it.

This is what i found on my iPod:

 PDAT(12) bit 3 -> USB plugged (Vbus detected is supposed)
 PDAT(11) bits 4:5 -> charge status: CHARGING, DISCHARGING, TOPOFF and UNKNOWN (this state is infrequent and spurious so cannot figure what it means)
 I didn't found a GPIO where the external adaptor presence is reflected but it cat be retrieved from PMU via I2C bus
 When external adapter is present the charge status is *always* anything but DISCHARGING
 Charging states are sometimes erratic for USB charging.

Using I2C on ISRs seems unsafe (see holdswitch-poll.patch), so i choose not to use it on this patch, what the patch does is:

1) usb_detect() returns USB_INSERTED/USB_EXTRACTED when USB is plugged/unplugged.
2) charging:state(), return true when charge state is CHARGING, false otherwise.
3) power_input_status() must return which chargers are present:

  a) if usb is inserted -> return USB as the only charger present (external adapter may be present or not, i think currently there is no serious impact when this information is omitted)
  b) if no usb inserted but charge status is anything but DISCHARGING -> return external adapter as present

4) Before entering standby state, the PMU is configured to powerup the iPod when USB insertion is detected, on my iPod EXT pins are: EXTON1=button press and holdswitch lock, EXTON2=USB Vbus, EXTON3=Dock Station, so PMU could also be configured to powerup when inserting on a dock station.

With the previous info the USB stack should work correctly, i think it does for me.

The PMU supports external adaptor/usb charging capabilities, but probably they are not using all of them, i read somewhere there is a 4066 inside.

I wrote some code to get complete charger information from PMU, but remember actually it isn't irq safe:

#define IPOD_6G_PRESENT_DOCK_STATION() (pmu_read(PCF5063X_REG_OOCSTAT) & 8)
#define IPOD_6G_PRESENT_USB() (pmu_read(PCF5063X_REG_OOCSTAT) & 4)
#define IPOD_6G_PRESENT_ADAPTOR() (pmu_read(PCF5063X_REG_MBCS1) & PCF5063X_MBCS1_ADAPTPRES)

unsigned int power_input_status(void)
{

  unsigned int power_input = POWER_INPUT_NONE;
  if (IPOD_6G_PRESENT_USB())
      power_input |= POWER_INPUT_USB_CHARGER;
  if (IPOD_6G_PRESENT_ADAPTOR())
      power_input |= POWER_INPUT_MAIN_CHARGER;
  return power_input;

}

momom commented on 2012-02-24 17:59

I tried it, Ipod (160 thick) powers on when adapter or pc is connected but it always goes in usb disk mode even if car mode is set to on. When adapters is disconnected player goes in pause, but when reconnected, even for 1 second, again usb mode. Can't resume as I always have to hold a button during connection. Really annoying as I use a cable and a cradle in car. My adapters are generic, don't have voltage on D+ D- of USB

Hi,i tested this patch on a dock station and it seems to work correctly, it can detect when i plug the dock and/or the AC adaptor and/or the usb cable (through the dock). When i connect the usb cable (AC adaptor plugged or not) then the USB charging/mounting screen appears, i think it is the desired behaviour, it also means the usb and AC adaptor are connected in a different way into the dock station, i figure the AC adaptor is using the firewire input, but not sure it also could be different resistor configuration (see dock connector pinout).

I think your car adapter is charging the ipod using usb, to verify it you can power-off the iPod and if it boots when you connect your car power adaptor then it is charging as USB, A quick search reveals most car adapters are using usb, you can find a few for the Classic claiming they use firewire pins, some people says they works ok, other people had bad experience and heating issues, Apple says there is no FW support on Classic.

Still i believe my dock is charging the iPod using FW pins (not sure, don't have tools to verify it now), my AC adapter is 7V/800mA, probably this voltage is regulated into dock to 5V or so. If FW pins are active then I don't know if it is dangerous to use 12V FW car adapters, it depends on how hardware is designed, at this moment i think it is safe to stay away if voltage is more than 5V, some feedback of people using FW car adaptors (if any) will be helpful.

This patch doesn't work if you use USB car adaptors, it detects if there is USB and/or AC inserted, but cannot detect if USB is charger-only (there is no USB host connected) to bypass the charging/mounting screen, i suppose it could be done at usb generic driver but didn't look at that code and don't know if it is possible and should be done, must ask USB stack developers for that.

This patch should work on dock stations and FW(?) car adaptors but not in USB card adaptors, so please verify if you are really using an USB adaptor and let me know, i could be wrong and there is some configuration resistors or other things involved instead FW pins.

What probably i missed was to power-up the iPod when plugged into the dock/cradle, it is easy to include on a next v2 patch.

momom commented on 2012-03-06 08:55

Well, as far as I read charging function should be started when there is 2.8 Volt on D- and 2.0 on D+ of usb data connection (pin 2 and 3), if there is only 5.0 Volt on usb supply (pin 1 and 4) then it goes in usb mode (and charging is limited to usb 500 mAh)- on firewire there is no function. Docking station should use pin 21 of ipod connector. Would be nice to have a patch that does the following when usb adapter (with 2.8 and 2.0 on data pins) and car mode set to on: charge, don't go in usb, start reproduction, if power is not present for more then 10 second (example) go in pause, power off after period in setting. With car mode set off but connected to charger (with 2.8 and 2.0 on data) charge but don't power up, if connected to pc limited charge and usb mode.
All this because standard is the usb cable and many users use the line out (if not headphone out) for signal and usb cable to charge.

The problem is Classic hardware is not informing (or we don't know where is this info) if USB is attached to a USB-Host or not, so at this stage it cannot be detected. The patch you are suggesting (do not enter USB mount screen when car mode is on, or similar) should be implemented at generic USB driver level and maybe as a menu option, i think this issue is the same as  FS#11917  (iPod nano 2g charger detection) and needs a general solution for all targets.

This may be an unreasonable suggestion, and I am sure it would require
intervention from the USB folks, and, probably at a higher architectural
level. I have only recently checked out the code and am starting to
poke around in it. Nonetheless, there are other devices out there that
only go into disk / mount mode when they detect that the host is
attempting to mount them and exit disk mode when they are "safely
removed" from under software control by the hardware. My investigation
of what this entails (on linux) suggests that the device could go into
disk mode when the USB host sends the first 'read' request (reading
block 0 of the disk to obtain the partition table) and exiting disk mode
when the host sends a CLEAR_FEATURE / Port Enable request or some such
thing. On linux (I have not tested this elsewhere) once the Safely
Disconnect sequence completes, the iPod no longer shows up in lsusb and
needs to be unplugged and plugged back in to get it back.

Taking an approach like this would accomplish several things:

  1. Determination of whether to be in the mount mode would no longer

be device specific, mount entry would be as a result of disk

    activity initiated from the host and mount exit would be the
    result of USB soft-disconnection
  1. Connection to a charger or docking device could never activate

mount mode because a charger will never send any USB requests and

    a docking station will not send disk IO commands even if, on some
    device, a docking station sends USB requests.

I recognize that this would take extra effort up front, but, in the long
run it would make rockbox a better product and would improve
portability.

If there is anyone already investigating this avenue or if this avenue
has been attempted in the past and dropped for some reason, I would love
to hear about it before I sink time into trying to implement this. If
there is someone with more knowledge of the USB mounting / safe removal
protocols or someone who would be willing to talk (offline) with me
about how this might fit into the rockbox architecture, that would be
great as well.

Hi there, how do I apply the patch :)

No programming experience at all. But I promise I'll post my results here.

SITUATION NOW:
at the moment I have an Ipod Classic with the RockBox for the classic version. When I plug it in my car I can charge it via USB or listen via the headphone plug but not both at the same time. I used to be able to do it with the normal Ipod software (you know the crappy one that tells you what is allowed and what not).

So I would liek to try the patch, but how…

Bulent, you can manually work around this problem by pressing and holding any button on your iPod Classic while you plug it in to the USB charger. This will prevent it from entering data transfer mode and you will be able to listen to music while it charges. I would recommend holding a button other than the play button though, as holding the play button shuts down your iPod.

He thanks that simple trick worked on my pc. I'll try it in my car as well, would be a big relieve! Thanks B.! No patch applying at the moment than.

Is it possible to apply this patch to the offical iPod classic build?
That would be very helpful!

momom commented on 2014-02-08 20:33

It is allready in classic build - car mode works on Ipod classic (it sets pause when you disconnect power and resumes when you reconnect), the problem remains: you have to long push a button to prevent USB data mode

Hi there, does somebody know how to fix this. Because it is quite irritating to do this al the time - keep a longpress - especially in the car when driving etc(where I have my rockboxipod). Would be wonderfull!!!!

That's why I was aksing too! I'm using the car mode for turning off the Ipod but starting the car is not that esay when you need to press the menu button.
Maybe there could be an option that reverses the menu behaviour: Pressing menu and inserting USB activates disk mode?
Cheers

Loading...

Available keyboard shortcuts

Tasklist

Task Details

Task Editing