2 * nokia.c -- Nokia Composite Gadget Driver
4 * Copyright (C) 2008 Nokia Corporation
5 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
7 * This gadget driver borrows from serial.c which is:
9 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
10 * Copyright (C) 2008 by David Brownell
11 * Copyright (C) 2008 by Nokia Corporation
13 * This software is distributed under the terms of the GNU General
14 * Public License ("GPL") as published by the Free Software Foundation,
15 * version 2 of that License.
18 #include <linux/kernel.h>
19 #include <linux/utsname.h>
20 #include <linux/device.h>
21 #include <linux/tty.h>
22 #include <linux/tty_flip.h>
27 #include "gadget_chips.h"
29 #include <asm/mach-types.h>
33 #define NOKIA_VERSION_NUM 0x0211
34 #define NOKIA_LONG_NAME "N900 (PC-Suite Mode)"
36 /*-------------------------------------------------------------------------*/
39 * Kbuild is not very cooperative with respect to linking separately
40 * compiled library objects into one module. So for now we won't use
41 * separate compilation ... ensuring init/exit sections work to shrink
42 * the runtime footprint, and giving us at least some parts of what
43 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
45 #include "composite.c"
46 #include "usbstring.c"
48 #include "epautoconf.c"
58 /*-------------------------------------------------------------------------*/
60 #define NOKIA_VENDOR_ID 0x0421 /* Nokia */
61 #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
63 /* string IDs are assigned dynamically */
65 #define STRING_MANUFACTURER_IDX 0
66 #define STRING_PRODUCT_IDX 1
67 #define STRING_DESCRIPTION_IDX 2
69 static char manufacturer_nokia[] = "Nokia";
70 static const char product_nokia[] = NOKIA_LONG_NAME;
71 static const char description_nokia[] = "PC-Suite Configuration";
73 static struct usb_string strings_dev[] = {
74 [STRING_MANUFACTURER_IDX].s = manufacturer_nokia,
75 [STRING_PRODUCT_IDX].s = NOKIA_LONG_NAME,
76 [STRING_DESCRIPTION_IDX].s = description_nokia,
80 static struct usb_gadget_strings stringtab_dev = {
81 .language = 0x0409, /* en-us */
82 .strings = strings_dev,
85 static struct usb_gadget_strings *dev_strings[] = {
90 static struct usb_device_descriptor device_desc = {
91 .bLength = USB_DT_DEVICE_SIZE,
92 .bDescriptorType = USB_DT_DEVICE,
93 .bcdUSB = __constant_cpu_to_le16(0x0200),
94 .bDeviceClass = USB_CLASS_COMM,
95 .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID),
96 .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID),
97 /* .iManufacturer = DYNAMIC */
98 /* .iProduct = DYNAMIC */
99 .bNumConfigurations = 1,
102 /*-------------------------------------------------------------------------*/
105 MODULE_DESCRIPTION("Nokia composite gadget driver for N900");
106 MODULE_AUTHOR("Felipe Balbi");
107 MODULE_LICENSE("GPL");
109 /*-------------------------------------------------------------------------*/
111 static u8 hostaddr[ETH_ALEN];
113 static int __init nokia_bind_config(struct usb_configuration *c)
117 status = phonet_bind_config(c);
119 printk(KERN_DEBUG "could not bind phonet config\n");
121 status = obex_bind_config(c, 0);
123 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
125 status = obex_bind_config(c, 1);
127 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
129 status = acm_bind_config(c, 2);
131 printk(KERN_DEBUG "could not bind acm config\n");
133 status = ecm_bind_config(c, hostaddr);
135 printk(KERN_DEBUG "could not bind ecm config\n");
140 static struct usb_configuration nokia_config_500ma_driver = {
142 .bind = nokia_bind_config,
143 .bConfigurationValue = 1,
144 /* .iConfiguration = DYNAMIC */
145 .bmAttributes = USB_CONFIG_ATT_ONE,
146 .bMaxPower = 250, /* 500mA */
149 static struct usb_configuration nokia_config_100ma_driver = {
151 .bind = nokia_bind_config,
152 .bConfigurationValue = 2,
153 /* .iConfiguration = DYNAMIC */
154 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
155 .bMaxPower = 50, /* 100 mA */
158 static int __init nokia_bind(struct usb_composite_dev *cdev)
161 struct usb_gadget *gadget = cdev->gadget;
164 status = gphonet_setup(cdev->gadget);
168 status = gserial_setup(cdev->gadget, 3);
172 status = gether_setup(cdev->gadget, hostaddr);
176 status = usb_string_id(cdev);
179 strings_dev[STRING_MANUFACTURER_IDX].id = status;
181 device_desc.iManufacturer = status;
183 status = usb_string_id(cdev);
186 strings_dev[STRING_PRODUCT_IDX].id = status;
188 device_desc.iProduct = status;
190 /* config description */
191 status = usb_string_id(cdev);
194 strings_dev[STRING_DESCRIPTION_IDX].id = status;
196 nokia_config_500ma_driver.iConfiguration = status;
197 nokia_config_100ma_driver.iConfiguration = status;
199 /* set up other descriptors */
200 gcnum = usb_gadget_controller_number(gadget);
202 device_desc.bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM);
204 /* this should only work with hw that supports altsettings
205 * and several endpoints, anything else, panic.
207 pr_err("nokia_bind: controller '%s' not recognized\n",
212 /* finaly register the configuration */
213 status = usb_add_config(cdev, &nokia_config_500ma_driver);
217 status = usb_add_config(cdev, &nokia_config_100ma_driver);
221 INFO(cdev, "%s\n", NOKIA_LONG_NAME);
235 static int __exit nokia_unbind(struct usb_composite_dev *cdev)
244 static struct usb_composite_driver nokia_driver = {
247 .strings = dev_strings,
249 .unbind = __exit_p(nokia_unbind),
252 static int __init nokia_init(void)
254 return usb_composite_register(&nokia_driver);
256 module_init(nokia_init);
258 static void __exit nokia_cleanup(void)
260 usb_composite_unregister(&nokia_driver);
262 module_exit(nokia_cleanup);