From foo@baz Tue Apr 9 12:12:43 2002 Date: Thu, 23 Aug 2007 15:26:51 -0700 To: Greg KH From: Greg Kroah-Hartman Subject: USB: driver for iphone charging Here's a driver originally by Matt Colyer , based on my berry_charge code that adds support for charging the iphone when it is plugged into a Linux machine. As I don't have an iphone, can someone who does please test this out and let me know if it works properly or not? Cc: Matt Colyer Signed-off-by: Greg Kroah-Hartman --- drivers/usb/Makefile | 1 drivers/usb/misc/Kconfig | 11 ++++ drivers/usb/misc/Makefile | 1 drivers/usb/misc/iphone.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_USB_EMI62) += misc/ obj-$(CONFIG_USB_FTDI_ELAN) += misc/ obj-$(CONFIG_USB_IDMOUSE) += misc/ obj-$(CONFIG_USB_IOWARRIOR) += misc/ +obj-$(CONFIG_USB_IPHONE) += misc/ obj-$(CONFIG_USB_LCD) += misc/ obj-$(CONFIG_USB_LD) += misc/ obj-$(CONFIG_USB_LED) += misc/ --- a/drivers/usb/misc/Kconfig +++ b/drivers/usb/misc/Kconfig @@ -99,6 +99,17 @@ config USB_BERRY_CHARGE To compile this driver as a module, choose M here: the module will be called berry_charge. +config USB_IPHONE + tristate "USB iPhone recharge support" + depends on USB + help + Say Y here if you want to connect a iPhone device to your + computer's USB port and have it automatically switch to "recharge" + mode. + + To compile this driver as a module, choose M here: the + module will be called iphone. + config USB_LED tristate "USB LED driver support" depends on USB --- a/drivers/usb/misc/Makefile +++ b/drivers/usb/misc/Makefile @@ -14,6 +14,7 @@ obj-$(CONFIG_USB_EMI62) += emi62.o obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan.o obj-$(CONFIG_USB_IDMOUSE) += idmouse.o obj-$(CONFIG_USB_IOWARRIOR) += iowarrior.o +obj-$(CONFIG_USB_IPHONE) += iphone.o obj-$(CONFIG_USB_LCD) += usblcd.o obj-$(CONFIG_USB_LD) += ldusb.o obj-$(CONFIG_USB_LED) += usbled.o --- /dev/null +++ b/drivers/usb/misc/iphone.c @@ -0,0 +1,107 @@ +/* + * USB iPhone module + * + * Copyright (C) 2007 Greg Kroah-Hartman + * Copyright (C) 2007 Matt Colyer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#include +#include +#include +#include +#include +#include + +#define APPLE_VENDOR 0x05ac +#define IPHONE 0x1290 + +static int debug; + +#ifdef dbg +#undef dbg +#endif +#define dbg(dev, format, arg...) \ + if (debug) \ + dev_printk(KERN_DEBUG , dev , format , ## arg) + +static struct usb_device_id id_table [] = { + { USB_DEVICE(APPLE_VENDOR, IPHONE) }, + { }, /* Terminating entry */ +}; +MODULE_DEVICE_TABLE(usb, id_table); + +static int select_configuration(struct usb_device *udev) +{ + char *dummy_buffer = kzalloc(2, GFP_KERNEL); + int retval; + + if (!dummy_buffer) + return -ENOMEM; + + dbg(&udev->dev, "Calling set_configuration\n"); + retval = usb_driver_set_configuration(udev, 3); + if (retval) { + dev_err(&udev->dev, "Set Configuration failed :%d.\n", retval); + goto exit; + } + + dbg(&udev->dev, "Sending first magic command\n"); + retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x40, 0x40, + 0x6400, 0, dummy_buffer, 0, 100); + +exit: + kfree(dummy_buffer); + return retval; +} + +static int iphone_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + struct usb_device *udev = interface_to_usbdev(intf); + + if (udev->actconfig->desc.bConfigurationValue == 3) { + dbg(&udev->dev, "Configuration changed"); + return -ENODEV; + } + + /* turn the power on */ + select_configuration(udev); + + /* we don't really want to bind to the device, userspace programs can + * handle the syncing just fine, so get outta here. */ + return -ENODEV; +} + +static void iphone_disconnect(struct usb_interface *intf) +{ +} + +static struct usb_driver iphone_driver = { + .name = "iphone", + .probe = iphone_probe, + .disconnect = iphone_disconnect, + .id_table = id_table, +}; + +static int __init iphone_init(void) +{ + return usb_register(&iphone_driver); +} + +static void __exit iphone_exit(void) +{ + usb_deregister(&iphone_driver); +} + +module_init(iphone_init); +module_exit(iphone_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Matt Colyer "); +module_param(debug, bool, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(debug, "Debug enabled or not");