How to leave a usb port powered during shutdown for charging mobile?

My Sony VAIO Laptop has a feature which will allow me to keep one USB port powered even when my laptop is shut down. It is given in the manual here. It can be switched on or off from the Vaio software which came with pre-installed Windows.

In the past, when I was dual booting with Windows, I could enable it by booting into Windows, and it would stay on, even after using Ubuntu several times. For some reason it stopped working recently. But I don't have Windows anymore, and would like to re-enable it from Ubuntu. It would be fun if I could switch it on manually from Linux. I digged a lot on google, especially for information on my motherboard(HannStar J MV-6 94V-0), and came up with its schematics in a Vietnamese site. I specifically mentions USB charging. But I am having no idea as to how to use the information.

Lot of people are suggesting that it can be enabled from the BIOS, but I have checked again and do not see anything in the BIOS. But I also observed that BIOS has very few fields, making me suspect that BIOS features might be hidden. I will try to unlock them. In the mean time, output of dmidecode is appended towards end of the question.

I don't know if this feature requires special hardware support, but anyways it is possible on my machine. Smart phones tend to go low on battery fast, and you could always connect it to the laptop in your bag, and charge it on the move when you are in college or traveling. That would not only be cool and handy, but also save money because I wont have to buy a power bank.

Here is the collected data:

  • dmidecode output

  • Kernel messages (loading sony-laptop with debug=1)

  • Content of /sys/devices/platform/sony-laptop/ and /proc/acpi/

  • After upgrading to 3.16.0-38-generic as suggested by Sneetsher,, uploaded new the kernel messages

    Also after the upgrage, I see usb_charge, but with value 1 of:

      cat /sys/devices/platform/sony-laptop/usb_charge
    

    but when I tried toggling it to 0 It still does not activate USB charging, but simply resets back to 1 when I check again using cat. But it should have worked because I found a c program and a shell script doing the same. I've noticed that I can write only 0 and one and if I write something else like suppose 2, I'll get:

    tee: /sys/devices/platform/sony-laptop/usb_charge: Invalid argument

  • Content of /sys/devices/platform/sony-laptop/ and /proc/acpi/ after kernel upgrade.

I manually booted into kernel 3.18, but the issue is still there. By the guidance of Sneetsher, I've filed a bug report here.


It's better to start where others stopped with sony-laptop Linux kernel module.

  1. Check if it's loaded

    lsmod | grep sony
    
  2. If not, load it

    sudo modprobe sony-laptop
    
  3. Check if there any corresponding entry/function for USB charging (usb_charge attribute got from source):

    tree /sys/devices/platform/sony-laptop/
    

    As I check the driver source, here are the corresponding functions (may be not for all models):

    ...
    static int sony_nc_usb_charge_setup(struct platform_device *pd);
    static void sony_nc_usb_charge_cleanup(struct platform_device *pd);
    ...
    

    Full functions definition here (portion from sony-laptop.c)

    0x0155 seems to be detected on you laptop from the kernel messages. The module created touchpad, battery_care_limiter, read-only handles, read-only battery_care_health SYSFS attributes but nothing else (including usb_charge).

    I checked the Ubuntu kernel source looking for USB charge function:

    • Ubuntu 14.04 Trusty (not yet added), kernel version 3.13

      If you are using this release, the easiest way is to install Utopic kernel:

      sudo apt-get install linux-generic-lts-utopic
      
    • Ubuntu 14.10 Utopic (it's there), kernel version 3.16

    If it is not there, it is hard/risky only if you are up to:

    Development:
    ------------
    
    If you want to help with the development of this driver (and
    you are not afraid of any side effects doing strange things with
    your ACPI BIOS could have on your laptop), load the driver and
    pass the option 'debug=1'.
    
    REPEAT: DON'T DO THIS IF YOU DON'T LIKE RISKY BUSINESS.
    
    In your kernel logs you will find the list of all ACPI methods
    the SNC device has on your laptop.
    

    See Readme file.

  4. As kernel upgraded by OP to 3.16.0-38-generic, usb_charge is created with some other SYSFS attributes.

    Reading similar driver kernel docs, sysfs-driver-samsung-laptop:

    What:     /sys/devices/platform/samsung/usb_charge
    Date:     December 1, 2011
    KernelVersion:    3.3
    Contact:  Corentin Chary <[email protected]>
    Description:  Use your USB ports to charge devices, even
          when your laptop is powered off.
          1 means enabled, 0 means disabled.
    

    To check current state:

    cat /sys/devices/platform/sony-laptop/usb_charge
    

    To disable it:

    echo 0 | sudo tee -a /sys/devices/platform/sony-laptop/usb_charge
    

    To enable it:

    echo 1 | sudo tee -a /sys/devices/platform/sony-laptop/usb_charge
    

References:

  • Sony Notebook Control Driver (SNC) Readme
  • sony-laptop source