Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[usb] Charging works also after first plugin. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

philippedeswert
Copy link

After the first plugin everything works, however unplug
and nothing works anymore until reboot. This patch seems
to at least re-enable charging. So the problem is most
likely related to some suspend-resume issue in the driver.

Signed-off-by: Philippe De Swert philippe.deswert@jollamobile.com

After the first plugin everything works, however unplug
and nothing works anymore until reboot. This patch seems
to at least re-enable charging. So the problem is most
likely related to some suspend-resume issue in the driver.

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
@filippz
Copy link
Owner

filippz commented Jul 7, 2015

First of all thanks for taking a crack at this!

This bug is known for some time now, and there is small info for it here: https://wiki.merproject.org/wiki/N9_Kernel_update_project. It states: "When PC is connected and usb gadget modules are used for the first time (g_zero & co) kernel is configured OK and draws 500mA from USB port, but on subsequent loading of gadget modules USB remains unconfigured and is limited to 100mA."

69f5f58 has more info: IIRC if kernel for example loads g_zero module when USB is connected for the first time, then it calls twl4030_set_power and everything is OK. But when one connects the USB for second time, kernel simply doesn't call that function, and I haven't found a way to "call" twl5031-bcc so it can configure current. If instead of g_zero kernel loads any other gadget module then twl4030_set_power is called and twl5031-bcc is notified. Maybe unloading those gadget modules when USB gets unplugged would be enough for kernel to reload them once USB gets connected again and call twl4030_set_power - the way it works when USB gets plugged in for the first time.

I have also tried to check if newer kernels have some references about this behaviour but I was unsuccessful in finding any commit or bug report - so this behaviour may well be "by design", or we simply are doing something wrong and preventing gadget driver to do it's job on disconnect.

It has been some time since I last looked at this one, and maybe I'm mistaken, but can you please check if unloading g_zero (or whatever gets loaded) and loading same (or some other) gadget module gets the job done? Maybe unloading gadget modules when USB gets disconnected is the way to go...

Thank you once more!

@filippz
Copy link
Owner

filippz commented Jul 23, 2015

I'm still trying to figure this one out...

I've found out that call to pm_runtime_get_sync in function musb_gadget_start of musb_gadget.c (https://github.com/filippz/kernel-adaptation-n950-n9/blob/master/drivers/usb/musb/musb_gadget.c#L1927) should cause twl4030_phy_resume to be called (not directly), but it works only on first connect because musb->controller->power.usage_count.counter (monitored just before that line) grows by 1 on ever plug/unplug sequence. After cable gets disconnected, function musb_gadget_stop calls for pm_runtime_put (https://github.com/filippz/kernel-adaptation-n950-n9/blob/master/drivers/usb/musb/musb_gadget.c#L2070), and musb->controller->power.usage_count.counter is 0 which is OK.

Seems that somewhere else (after musb_gadget_stop) something calls for pm_runtime_get for musb->controller, but I'm unable to figure out where/when exactly - maybe you can take a look?

@philippedeswert
Copy link
Author

Yes need to have a better look at it too, just have not gotten much time to do so lately. It's a good theory, will need to get over the code again and dig up my n9 again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants