From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, linux-usb-devel@lists.sourceforge.net
Cc: Matt Colyer <matt@colyer.name>, jeffm@suse.de
Subject: [RFC] USB: driver for iphone charging
Date: Thu, 23 Aug 2007 15:45:14 -0700 [thread overview]
Message-ID: <20070823224514.GA25830@kroah.com> (raw)
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?
Matt, I fixed up the formatting of your original driver, fixed a sparse
warning, and the memory leak (which happens to also be in the
berry_charge driver, I'll go fix that too...)
Cc: Matt Colyer <matt@colyer.name>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
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
@@ -40,6 +40,7 @@ obj-$(CONFIG_USB_FTDI_ELAN) += misc/
obj-$(CONFIG_USB_GOTEMP) += 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
@@ -15,6 +15,7 @@ obj-$(CONFIG_USB_FTDI_ELAN) += ftdi-elan
obj-$(CONFIG_USB_GOTEMP) += gotemp.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 <gregkh@suse.de>
+ * Copyright (C) 2007 Matt Colyer <matt@colyer.name>
+ *
+ * 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 <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+
+#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 <matt@colyer.name>");
+module_param(debug, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(debug, "Debug enabled or not");
next reply other threads:[~2007-08-23 22:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-23 22:45 Greg KH [this message]
2007-08-24 7:20 ` [RFC] USB: driver for iphone charging Oliver Neukum
2007-08-24 14:08 ` [linux-usb-devel] " Alan Stern
2007-08-24 14:23 ` Oliver Neukum
2007-08-24 18:36 ` Greg KH
2007-08-24 18:35 ` Greg KH
2007-08-24 18:55 ` Alan Stern
2007-08-25 2:21 ` Matt Colyer
[not found] <8VtFd-7mx-51@gated-at.bofh.it>
2007-08-24 10:51 ` Bodo Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070823224514.GA25830@kroah.com \
--to=greg@kroah.com \
--cc=jeffm@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb-devel@lists.sourceforge.net \
--cc=matt@colyer.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.