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"
42 #include "usbstring.c"
44 #include "epautoconf.c"
54 /*-------------------------------------------------------------------------*/
56 #define NOKIA_VENDOR_ID 0x0421 /* Nokia */
57 #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
59 /* string IDs are assigned dynamically */
61 #define STRING_MANUFACTURER_IDX 0
62 #define STRING_PRODUCT_IDX 1
63 #define STRING_DESCRIPTION_IDX 2
65 static char manufacturer_nokia
[] = "Nokia";
66 static const char product_nokia
[] = NOKIA_LONG_NAME
;
67 static const char description_nokia
[] = "PC-Suite Configuration";
69 static struct usb_string strings_dev
[] = {
70 [STRING_MANUFACTURER_IDX
].s
= manufacturer_nokia
,
71 [STRING_PRODUCT_IDX
].s
= NOKIA_LONG_NAME
,
72 [STRING_DESCRIPTION_IDX
].s
= description_nokia
,
76 static struct usb_gadget_strings stringtab_dev
= {
77 .language
= 0x0409, /* en-us */
78 .strings
= strings_dev
,
81 static struct usb_gadget_strings
*dev_strings
[] = {
86 static struct usb_device_descriptor device_desc
= {
87 .bLength
= USB_DT_DEVICE_SIZE
,
88 .bDescriptorType
= USB_DT_DEVICE
,
89 .bcdUSB
= __constant_cpu_to_le16(0x0200),
90 .bDeviceClass
= USB_CLASS_COMM
,
91 .idVendor
= __constant_cpu_to_le16(NOKIA_VENDOR_ID
),
92 .idProduct
= __constant_cpu_to_le16(NOKIA_PRODUCT_ID
),
93 /* .iManufacturer = DYNAMIC */
94 /* .iProduct = DYNAMIC */
95 .bNumConfigurations
= 1,
98 /*-------------------------------------------------------------------------*/
101 MODULE_DESCRIPTION("Nokia composite gadget driver for N900");
102 MODULE_AUTHOR("Felipe Balbi");
103 MODULE_LICENSE("GPL");
105 /*-------------------------------------------------------------------------*/
107 static u8 hostaddr
[ETH_ALEN
];
109 static int __init
nokia_bind_config(struct usb_configuration
*c
)
113 status
= phonet_bind_config(c
);
115 printk(KERN_DEBUG
"could not bind phonet config\n");
117 status
= obex_bind_config(c
, 0);
119 printk(KERN_DEBUG
"could not bind obex config %d\n", 0);
121 status
= obex_bind_config(c
, 1);
123 printk(KERN_DEBUG
"could not bind obex config %d\n", 0);
125 status
= acm_bind_config(c
, 2);
127 printk(KERN_DEBUG
"could not bind acm config\n");
129 status
= ecm_bind_config(c
, hostaddr
);
131 printk(KERN_DEBUG
"could not bind ecm config\n");
136 static struct usb_configuration nokia_config_500ma_driver
= {
137 .label
= "Bus Powered",
138 .bConfigurationValue
= 1,
139 /* .iConfiguration = DYNAMIC */
140 .bmAttributes
= USB_CONFIG_ATT_ONE
,
141 .bMaxPower
= 250, /* 500mA */
144 static struct usb_configuration nokia_config_100ma_driver
= {
145 .label
= "Self Powered",
146 .bConfigurationValue
= 2,
147 /* .iConfiguration = DYNAMIC */
148 .bmAttributes
= USB_CONFIG_ATT_ONE
| USB_CONFIG_ATT_SELFPOWER
,
149 .bMaxPower
= 50, /* 100 mA */
152 static int __init
nokia_bind(struct usb_composite_dev
*cdev
)
155 struct usb_gadget
*gadget
= cdev
->gadget
;
158 status
= gphonet_setup(cdev
->gadget
);
162 status
= gserial_setup(cdev
->gadget
, 3);
166 status
= gether_setup(cdev
->gadget
, hostaddr
);
170 status
= usb_string_id(cdev
);
173 strings_dev
[STRING_MANUFACTURER_IDX
].id
= status
;
175 device_desc
.iManufacturer
= status
;
177 status
= usb_string_id(cdev
);
180 strings_dev
[STRING_PRODUCT_IDX
].id
= status
;
182 device_desc
.iProduct
= status
;
184 /* config description */
185 status
= usb_string_id(cdev
);
188 strings_dev
[STRING_DESCRIPTION_IDX
].id
= status
;
190 nokia_config_500ma_driver
.iConfiguration
= status
;
191 nokia_config_100ma_driver
.iConfiguration
= status
;
193 /* set up other descriptors */
194 gcnum
= usb_gadget_controller_number(gadget
);
196 device_desc
.bcdDevice
= cpu_to_le16(NOKIA_VERSION_NUM
);
198 /* this should only work with hw that supports altsettings
199 * and several endpoints, anything else, panic.
201 pr_err("nokia_bind: controller '%s' not recognized\n",
206 /* finally register the configuration */
207 status
= usb_add_config(cdev
, &nokia_config_500ma_driver
,
212 status
= usb_add_config(cdev
, &nokia_config_100ma_driver
,
217 dev_info(&gadget
->dev
, "%s\n", NOKIA_LONG_NAME
);
231 static int __exit
nokia_unbind(struct usb_composite_dev
*cdev
)
240 static struct usb_composite_driver nokia_driver
= {
243 .strings
= dev_strings
,
244 .unbind
= __exit_p(nokia_unbind
),
247 static int __init
nokia_init(void)
249 return usb_composite_probe(&nokia_driver
, nokia_bind
);
251 module_init(nokia_init
);
253 static void __exit
nokia_cleanup(void)
255 usb_composite_unregister(&nokia_driver
);
257 module_exit(nokia_cleanup
);