2 * nokia.c -- Nokia Composite Gadget Driver
4 * Copyright (C) 2008-2010 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>
25 #include "gadget_chips.h"
29 #define NOKIA_VERSION_NUM 0x0211
30 #define NOKIA_LONG_NAME "N900 (PC-Suite Mode)"
32 /*-------------------------------------------------------------------------*/
35 * Kbuild is not very cooperative with respect to linking separately
36 * compiled library objects into one module. So for now we won't use
37 * separate compilation ... ensuring init/exit sections work to shrink
38 * the runtime footprint, and giving us at least some parts of what
39 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
41 #include "composite.c"
51 /*-------------------------------------------------------------------------*/
52 USB_GADGET_COMPOSITE_OPTIONS();
54 #define NOKIA_VENDOR_ID 0x0421 /* Nokia */
55 #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
57 /* string IDs are assigned dynamically */
59 #define STRING_MANUFACTURER_IDX 0
60 #define STRING_PRODUCT_IDX 1
61 #define STRING_DESCRIPTION_IDX 2
63 static char manufacturer_nokia[] = "Nokia";
64 static const char product_nokia[] = NOKIA_LONG_NAME;
65 static const char description_nokia[] = "PC-Suite Configuration";
67 static struct usb_string strings_dev[] = {
68 [STRING_MANUFACTURER_IDX].s = manufacturer_nokia,
69 [STRING_PRODUCT_IDX].s = NOKIA_LONG_NAME,
70 [STRING_DESCRIPTION_IDX].s = description_nokia,
74 static struct usb_gadget_strings stringtab_dev = {
75 .language = 0x0409, /* en-us */
76 .strings = strings_dev,
79 static struct usb_gadget_strings *dev_strings[] = {
84 static struct usb_device_descriptor device_desc = {
85 .bLength = USB_DT_DEVICE_SIZE,
86 .bDescriptorType = USB_DT_DEVICE,
87 .bcdUSB = __constant_cpu_to_le16(0x0200),
88 .bDeviceClass = USB_CLASS_COMM,
89 .idVendor = __constant_cpu_to_le16(NOKIA_VENDOR_ID),
90 .idProduct = __constant_cpu_to_le16(NOKIA_PRODUCT_ID),
91 /* .iManufacturer = DYNAMIC */
92 /* .iProduct = DYNAMIC */
93 .bNumConfigurations = 1,
96 /*-------------------------------------------------------------------------*/
99 MODULE_DESCRIPTION("Nokia composite gadget driver for N900");
100 MODULE_AUTHOR("Felipe Balbi");
101 MODULE_LICENSE("GPL");
103 /*-------------------------------------------------------------------------*/
105 static u8 hostaddr[ETH_ALEN];
107 static int __init nokia_bind_config(struct usb_configuration *c)
111 status = phonet_bind_config(c);
113 printk(KERN_DEBUG "could not bind phonet config\n");
115 status = obex_bind_config(c, 0);
117 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
119 status = obex_bind_config(c, 1);
121 printk(KERN_DEBUG "could not bind obex config %d\n", 0);
123 status = acm_bind_config(c, 2);
125 printk(KERN_DEBUG "could not bind acm config\n");
127 status = ecm_bind_config(c, hostaddr);
129 printk(KERN_DEBUG "could not bind ecm config\n");
134 static struct usb_configuration nokia_config_500ma_driver = {
135 .label = "Bus Powered",
136 .bConfigurationValue = 1,
137 /* .iConfiguration = DYNAMIC */
138 .bmAttributes = USB_CONFIG_ATT_ONE,
139 .bMaxPower = 250, /* 500mA */
142 static struct usb_configuration nokia_config_100ma_driver = {
143 .label = "Self Powered",
144 .bConfigurationValue = 2,
145 /* .iConfiguration = DYNAMIC */
146 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
147 .bMaxPower = 50, /* 100 mA */
150 static int __init nokia_bind(struct usb_composite_dev *cdev)
153 struct usb_gadget *gadget = cdev->gadget;
156 status = gphonet_setup(cdev->gadget);
160 status = gserial_setup(cdev->gadget, 3);
164 status = gether_setup(cdev->gadget, hostaddr);
168 status = usb_string_ids_tab(cdev, strings_dev);
171 device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
172 device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
173 status = strings_dev[STRING_DESCRIPTION_IDX].id;
174 nokia_config_500ma_driver.iConfiguration = status;
175 nokia_config_100ma_driver.iConfiguration = status;
177 /* set up other descriptors */
178 gcnum = usb_gadget_controller_number(gadget);
180 device_desc.bcdDevice = cpu_to_le16(NOKIA_VERSION_NUM);
182 /* this should only work with hw that supports altsettings
183 * and several endpoints, anything else, panic.
185 pr_err("nokia_bind: controller '%s' not recognized\n",
190 /* finally register the configuration */
191 status = usb_add_config(cdev, &nokia_config_500ma_driver,
196 status = usb_add_config(cdev, &nokia_config_100ma_driver,
201 usb_composite_overwrite_options(cdev, &coverwrite);
202 dev_info(&gadget->dev, "%s\n", NOKIA_LONG_NAME);
216 static int __exit nokia_unbind(struct usb_composite_dev *cdev)
225 static __refdata struct usb_composite_driver nokia_driver = {
228 .strings = dev_strings,
229 .max_speed = USB_SPEED_HIGH,
231 .unbind = __exit_p(nokia_unbind),
234 static int __init nokia_init(void)
236 return usb_composite_probe(&nokia_driver);
238 module_init(nokia_init);
240 static void __exit nokia_cleanup(void)
242 usb_composite_unregister(&nokia_driver);
244 module_exit(nokia_cleanup);