Commit 4f3d729f authored by Bastien Nocera's avatar Bastien Nocera

linux: Enable iDevice fast-charge by default

Similarly to what the ipad_charge helper does:
https://github.com/mkorenkov/ipad_charge

This turns on fast charging for iDevices that draw more power than
originally enabled by the hardware.

#18
parent 49af045f
......@@ -203,7 +203,7 @@ if test x$with_backend = xlinux; then
AC_ARG_WITH(idevice, AS_HELP_STRING([--without-idevice],[Build without libimobiledevice]),
with_idevice=$withval,with_idevice=yes)
AS_IF([test "x$with_idevice" != "xno"],
[PKG_CHECK_MODULES(IDEVICE, libimobiledevice-1.0 >= 0.9.7 libplist >= 0.12, have_idevice=yes, have_idevice=no)],
[PKG_CHECK_MODULES(IDEVICE, libimobiledevice-1.0 >= 0.9.7 libplist >= 0.12 gusb, have_idevice=yes, have_idevice=no)],
[have_idevice=no])
AS_IF([test "x$have_idevice" = "xyes"],
[AC_DEFINE(HAVE_IDEVICE, 1, [Define to 1 if iDevice is going to be built])])
......
......@@ -36,6 +36,7 @@
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
#include <plist/plist.h>
#include <gusb.h>
#include "sysfs-utils.h"
#include "up-types.h"
......@@ -204,6 +205,51 @@ out:
return G_SOURCE_CONTINUE;
}
static void
enable_fast_charging (const char *bus, const char *dev)
{
GUsbContext *ctx;
GUsbDevice *device;
GError *error = NULL;
int busnum, devnum;
busnum = atoi (bus);
devnum = atoi (dev);
if (busnum == 0 || devnum == 0)
return;
ctx = g_usb_context_new (NULL);
if (!ctx)
return;
device = g_usb_context_find_by_bus_address (ctx, busnum, devnum, NULL);
if (!device)
goto out;
if (!g_usb_device_open (device, NULL))
goto out;
#define ADDITIONAL_VALUE_DEFAULT 1600
if (!g_usb_device_control_transfer (device,
G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
G_USB_DEVICE_REQUEST_TYPE_VENDOR,
G_USB_DEVICE_RECIPIENT_DEVICE,
0x40, 500, ADDITIONAL_VALUE_DEFAULT,
NULL, 0, NULL,
2000, NULL, &error)) {
g_warning ("Failed to enable fast charging: %s", error->message);
g_error_free (error);
} else {
g_debug ("Succeeded in enabling fast charging for iDevice on %s:%s",
bus, dev);
}
out:
g_clear_object (&device);
g_clear_object (&ctx);
}
/**
* up_device_idevice_coldplug:
*
......@@ -249,6 +295,9 @@ up_device_idevice_coldplug (UpDevice *device)
"has-history", TRUE,
NULL);
enable_fast_charging (g_udev_device_get_property (native, "BUSNUM"),
g_udev_device_get_property (native, "DEVNUM"));
idevice->priv->start_id = g_timeout_add_seconds (5, (GSourceFunc) up_device_idevice_start_poll_cb,
idevice);
g_source_set_name_by_id (idevice->priv->start_id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment