Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Jul 2007 16:11:08 -0600
From:      "Kirk Davis" <kirk.davis@epsb.ca>
To:        <freebsd-usb@freebsd.org>
Subject:   (Please test) New blackberry (uberry) driver.
Message-ID:  <DB9A31C316524A4A83E54A2C0D2065570413BCD2@Exchange24.EDU.epsb.ca>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hi,
	I have a new FreeBSD blackberry driver ready for testing.  This
patch is done against FreeBSD 6.2 (sorry I don't have a 7.0 machine
right now).  This driver started out as a port of the OpenBSD driver but
I have since updated it to handle the newer Blackberry devices (the ones
with a removable SD card).  

	The driver enables the 500mA charge rate and on the newer
devices it also enables dial mode so that the umass device is able to
mount the SD card.  I have tested it the following Blackberry models:
8100 (Pearl), 8830 (World Edition), and a 7250.

	There is still one small problem to over come. When a newer
Blackberry with an SD card is detected, the driver tells the Blackberry
to switch into dual mode and then the umass device picks up the SD card.
The SD card is not accessible though until the users allows it from the
blackberry. The umass device complains about this until I type in my
password on the Blackberry. Once I do then everything is fine and I can
mount the SD card. Is there a Quirk that can be added into the umass
driver to tell it not to query the SD card right away?

	This is my first driver so could one of the USB exports out
there look it over and see if the code looks OK.  

	Thanks for your help Warner and Hans!

---- Kirk 

Kirk Davis
Sr. Network Analyst, ITS
Edmonton Public Schools
Kirk.davis@epsb.ca
 




[-- Attachment #2 --]
diff -Nru /usr/local/cvsup-stable/src/sys/conf/files /usr/src/sys/conf/files
--- /usr/local/cvsup-stable/src/sys/conf/files	Fri Oct 20 23:28:50 2006
+++ /usr/src/sys/conf/files	Tue Jul 24 18:09:41 2007
@@ -997,6 +997,7 @@
 dev/usb/usbdi.c			optional usb
 dev/usb/usbdi_util.c		optional usb
 dev/usb/uscanner.c		optional uscanner
+dev/usb/uberry.c		optional uberry
 dev/usb/uvisor.c		optional uvisor ucom
 dev/usb/uvscom.c		optional uvscom ucom
 dev/utopia/idtphy.c		optional utopia
diff -Nru /usr/local/cvsup-stable/src/sys/dev/usb/uberry.c /usr/src/sys/dev/usb/uberry.c
--- /usr/local/cvsup-stable/src/sys/dev/usb/uberry.c	Wed Dec 31 17:00:00 1969
+++ /usr/src/sys/dev/usb/uberry.c	Mon Jul 30 15:31:29 2007
@@ -0,0 +1,217 @@
+/*	$OpenBSD: uberry.c,v 1.10 2007/06/14 10:11:15 mbalmer Exp $	*/
+
+/*-
+ * Copyright (c) 2006 Theo de Raadt <deraadt@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * 2007/7/30  added support for the new devices 8800 and 8100 Pearl (Kirk Davis)
+ * 2007/7/26  Initial port from OpenBSD to FreeBSD and cleanup (Kirk Davis)
+ */
+
+
+#include <sys/param.h>
+#include <sys/sockio.h>
+#include <sys/sysctl.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/timeout.h>
+#endif
+#include <sys/conf.h>
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <sys/device.h>
+
+#include <machine/bus.h>
+#include <machine/endian.h>
+#include <machine/intr.h>
+#elif defined(__FreeBSD__)
+#include <sys/ioccom.h>
+#include <sys/filio.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/endian.h>
+#endif
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#include <dev/usb/usbdevs.h>
+#elif defined(__FreeBSD__)
+#include "usbdevs.h"
+#endif 
+
+struct uberry_softc {
+#if defined(__FreeBSD__)
+	USBBASEDEVICE 			sc_dev;
+#else
+	struct device			sc_dev;
+#endif
+	usbd_device_handle		sc_udev;
+	usbd_interface_handle		sc_iface;
+#if defined(__FreeBSD__)
+	struct cdev *sc_dev_t;
+#endif
+};
+
+#define UBERRY_CONFIG_NO		1
+
+struct usb_devno const uberry_devices[] = {
+	{ USB_VENDOR_RIM, USB_PRODUCT_RIM_BLACKBERRY },
+	{ USB_VENDOR_RIM, USB_PRODUCT_RIM_PEARL }
+};
+
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+int uberry_activate(struct device *, enum devact); 
+
+struct cfdriver uberry_cd = { 
+	NULL, "uberry", DV_DULL 
+}; 
+
+const struct cfattach uberry_ca = { 
+	sizeof(struct uberry_softc), 
+	uberry_match, 
+	uberry_attach, 
+	uberry_detach, 
+	uberry_activate, 
+};
+#endif 
+
+static void do_charge(struct uberry_softc *sc);
+static void pearl_mode(struct uberry_softc *sc);
+
+USB_DECLARE_DRIVER(uberry);
+
+USB_MATCH(uberry)
+{
+	USB_MATCH_START(uberry, uaa);
+
+	if (uaa->iface != NULL)
+		return UMATCH_NONE;
+
+	return (usb_lookup(uberry_devices, uaa->vendor, uaa->product) != NULL) ?
+	    UMATCH_VENDOR_PRODUCT : UMATCH_NONE;
+}
+
+USB_ATTACH(uberry)
+{
+	USB_ATTACH_START(uberry, sc, uaa);
+	char devinfo[1024];
+
+        sc->sc_udev = uaa->device;
+	usb_device_descriptor_t *dd;
+
+        usbd_devinfo(sc->sc_udev, 0, devinfo);
+
+        USB_ATTACH_SETUP;
+
+	dd = usbd_get_device_descriptor(uaa->device);	
+
+	printf("\n%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
+	if ( UGETW(dd->idProduct) == USB_PRODUCT_RIM_PEARL ) {
+		(void) do_charge(sc);
+		printf("%s: Charging enabled\n", USBDEVNAME(sc->sc_dev));
+		pearl_mode(sc);
+	} else {
+
+		(void) do_charge(sc);
+		printf("%s: Charging enabled\n", USBDEVNAME(sc->sc_dev));
+	}
+
+	/* Enable the device, then it cannot idle, and will charge */
+	if (usbd_set_config_no(sc->sc_udev, UBERRY_CONFIG_NO, 1) != 0) {
+		printf("%s: could not set configuration no\n", 
+			USBDEVNAME(sc->sc_dev));
+		USB_ATTACH_ERROR_RETURN;
+	}
+
+	usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
+	    USBDEV(sc->sc_dev));
+	USB_ATTACH_SUCCESS_RETURN;
+}
+
+
+USB_DETACH(uberry)
+{
+	USB_DETACH_START(uberry, sc);
+
+	usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
+	    USBDEV(sc->sc_dev));
+
+	return (0);
+}
+
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+int
+uberry_activate(struct device *self, enum devact act)
+{
+	switch (act) {
+	case DVACT_ACTIVATE:
+		break;
+
+	case DVACT_DEACTIVATE:
+		break;
+	}
+	return 0;
+}
+#endif
+
+void
+pearl_mode(struct uberry_softc *sc)
+{
+	usb_device_request_t req;
+	char buffer[256];
+
+	req.bmRequestType = UT_READ_VENDOR_DEVICE;
+	req.bRequest = 0xa9;
+	USETW(req.wValue, 1);
+	USETW(req.wIndex, 1);
+	USETW(req.wLength, 2);
+	(void) usbd_do_request(sc->sc_udev, &req, &buffer);
+
+}
+
+void 
+do_charge(struct uberry_softc *sc)
+{
+	usb_device_request_t req;
+	char buffer[256];
+
+	req.bmRequestType = UT_READ_VENDOR_DEVICE;
+	req.bRequest = 0xa5;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, 1);
+	USETW(req.wLength, 2);
+	(void) usbd_do_request(sc->sc_udev, &req, &buffer);
+
+	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+	req.bRequest = 0xa2;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, 1);
+	USETW(req.wLength, 0);
+	(void) usbd_do_request(sc->sc_udev, &req, &buffer);
+
+}
+
+	
+
+#if defined(__FreeBSD__)
+DRIVER_MODULE(uberry, uhub, uberry_driver, uberry_devclass, usbd_driver_load, 0);
+#endif
+
diff -Nru /usr/local/cvsup-stable/src/sys/dev/usb/usbdevs /usr/src/sys/dev/usb/usbdevs
--- /usr/local/cvsup-stable/src/sys/dev/usb/usbdevs	Tue Nov 14 05:54:38 2006
+++ /usr/src/sys/dev/usb/usbdevs	Tue Jul 24 19:52:12 2007
@@ -487,6 +487,7 @@
 vendor EGALAX		0x0eef	eGalax
 vendor MICROTUNE	0x0f4d	Microtune
 vendor VTECH		0x0f88	VTech
+vendor RIM		0x0fca	Research In Motion
 vendor QUALCOMM2	0x1004	Qualcomm
 vendor GIGABYTE		0x1044	GIGABYTE
 vendor WESTERN		0x1058	Western Digital
@@ -1451,6 +1452,10 @@
 
 /* ReakTek products */
 product REALTEK USBKR100	0x8150	USBKR100 USB Ethernet (GREEN HOUSE)
+
+/* Research In Motion products */
+product RIM BLACKBERRY		0x0001  Blackberry
+product RIM PEARL		0x0006  Blackberry pearl
 
 /* Roland products */
 product ROLAND UM1		0x0009	UM-1 MIDI I/F
diff -Nru /usr/local/cvsup-stable/src/sys/modules/Makefile /usr/src/sys/modules/Makefile
--- /usr/local/cvsup-stable/src/sys/modules/Makefile	Mon Sep  4 00:14:57 2006
+++ /usr/src/sys/modules/Makefile	Tue Jul 24 18:14:25 2007
@@ -272,6 +272,7 @@
 	urio \
 	usb \
 	uscanner \
+	uberry \
 	utopia \
 	uvisor \
 	uvscom \
diff -Nru /usr/local/cvsup-stable/src/sys/modules/uberry/Makefile /usr/src/sys/modules/uberry/Makefile
--- /usr/local/cvsup-stable/src/sys/modules/uberry/Makefile	Wed Dec 31 17:00:00 1969
+++ /usr/src/sys/modules/uberry/Makefile	Tue Jul 24 18:14:54 2007
@@ -0,0 +1,8 @@
+# $FreeBSD: $
+
+.PATH: ${.CURDIR}/../../dev/usb
+
+KMOD=	uberry
+SRCS=	uberry.c opt_usb.h device_if.h bus_if.h usbdevs.h
+
+.include <bsd.kmod.mk>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DB9A31C316524A4A83E54A2C0D2065570413BCD2>