2 * USB BlackBerry charging module
4 * Copyright (C) 2007 Greg Kroah-Hartman <gregkh@suse.de>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
10 * Information on how to switch configs was taken by the bcharge.cc file
11 * created by the barry.sf.net project.
13 * bcharge.cc has the following copyright:
14 * Copyright (C) 2006, Net Direct Inc. (http://www.netdirect.ca/)
15 * and is released under the GPLv2.
20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/usb.h>
27 #define RIM_VENDOR 0x0fca
28 #define BLACKBERRY 0x0001
35 #define dbg(dev, format, arg...) \
37 dev_printk(KERN_DEBUG , dev , format , ## arg)
39 static struct usb_device_id id_table
[] = {
40 { USB_DEVICE(RIM_VENDOR
, BLACKBERRY
) },
41 { }, /* Terminating entry */
43 MODULE_DEVICE_TABLE(usb
, id_table
);
45 static int magic_charge(struct usb_device
*udev
)
47 char *dummy_buffer
= kzalloc(2, GFP_KERNEL
);
53 /* send two magic commands and then set the configuration. The device
54 * will then reset itself with the new power usage and should start
57 /* Note, with testing, it only seems that the first message is really
58 * needed (at least for the 8700c), but to be safe, we emulate what
59 * other operating systems seem to be sending to their device. We
60 * really need to get some specs for this device to be sure about what
63 dbg(&udev
->dev
, "Sending first magic command\n");
64 retval
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
65 0xa5, 0xc0, 0, 1, dummy_buffer
, 2, 100);
67 dev_err(&udev
->dev
, "First magic command failed: %d.\n",
72 dbg(&udev
->dev
, "Sending first magic command\n");
73 retval
= usb_control_msg(udev
, usb_rcvctrlpipe(udev
, 0),
74 0xa2, 0x40, 0, 1, dummy_buffer
, 0, 100);
76 dev_err(&udev
->dev
, "Second magic command failed: %d.\n",
81 dbg(&udev
->dev
, "Calling set_configuration\n");
82 retval
= usb_driver_set_configuration(udev
, 1);
84 dev_err(&udev
->dev
, "Set Configuration failed :%d.\n", retval
);
89 static int berry_probe(struct usb_interface
*intf
,
90 const struct usb_device_id
*id
)
92 struct usb_device
*udev
= interface_to_usbdev(intf
);
94 dbg(&udev
->dev
, "Power is set to %dmA\n",
95 udev
->actconfig
->desc
.bMaxPower
* 2);
97 /* check the power usage so we don't try to enable something that is
99 if ((udev
->actconfig
->desc
.bMaxPower
* 2) == 500) {
100 dbg(&udev
->dev
, "device is already charging, power is "
101 "set to %dmA\n", udev
->actconfig
->desc
.bMaxPower
* 2);
105 /* turn the power on */
108 /* we don't really want to bind to the device, userspace programs can
109 * handle the syncing just fine, so get outta here. */
113 static void berry_disconnect(struct usb_interface
*intf
)
117 static struct usb_driver berry_driver
= {
118 .name
= "berry_charge",
119 .probe
= berry_probe
,
120 .disconnect
= berry_disconnect
,
121 .id_table
= id_table
,
124 static int __init
berry_init(void)
126 return usb_register(&berry_driver
);
129 static void __exit
berry_exit(void)
131 usb_deregister(&berry_driver
);
134 module_init(berry_init
);
135 module_exit(berry_exit
);
137 MODULE_LICENSE("GPL");
138 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
139 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
140 MODULE_PARM_DESC(debug
, "Debug enabled or not");