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/device.h>
24 #include "gadget_chips.h"
28 #define NOKIA_VERSION_NUM 0x0211
29 #define NOKIA_LONG_NAME "N900 (PC-Suite Mode)"
31 /*-------------------------------------------------------------------------*/
34 * Kbuild is not very cooperative with respect to linking separately
35 * compiled library objects into one module. So for now we won't use
36 * separate compilation ... ensuring init/exit sections work to shrink
37 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
40 #define USB_FACM_INCLUDED
48 /*-------------------------------------------------------------------------*/
49 USB_GADGET_COMPOSITE_OPTIONS();
51 #define NOKIA_VENDOR_ID 0x0421 /* Nokia */
52 #define NOKIA_PRODUCT_ID 0x01c8 /* Nokia Gadget */
54 /* string IDs are assigned dynamically */
56 #define STRING_DESCRIPTION_IDX USB_GADGET_FIRST_AVAIL_IDX
58 static char manufacturer_nokia
[] = "Nokia";
59 static const char product_nokia
[] = NOKIA_LONG_NAME
;
60 static const char description_nokia
[] = "PC-Suite Configuration";
62 static struct usb_string strings_dev
[] = {
63 [USB_GADGET_MANUFACTURER_IDX
].s
= manufacturer_nokia
,
64 [USB_GADGET_PRODUCT_IDX
].s
= NOKIA_LONG_NAME
,
65 [USB_GADGET_SERIAL_IDX
].s
= "",
66 [STRING_DESCRIPTION_IDX
].s
= description_nokia
,
70 static struct usb_gadget_strings stringtab_dev
= {
71 .language
= 0x0409, /* en-us */
72 .strings
= strings_dev
,
75 static struct usb_gadget_strings
*dev_strings
[] = {
80 static struct usb_device_descriptor device_desc
= {
81 .bLength
= USB_DT_DEVICE_SIZE
,
82 .bDescriptorType
= USB_DT_DEVICE
,
83 .bcdUSB
= __constant_cpu_to_le16(0x0200),
84 .bDeviceClass
= USB_CLASS_COMM
,
85 .idVendor
= __constant_cpu_to_le16(NOKIA_VENDOR_ID
),
86 .idProduct
= __constant_cpu_to_le16(NOKIA_PRODUCT_ID
),
87 .bcdDevice
= cpu_to_le16(NOKIA_VERSION_NUM
),
88 /* .iManufacturer = DYNAMIC */
89 /* .iProduct = DYNAMIC */
90 .bNumConfigurations
= 1,
93 /*-------------------------------------------------------------------------*/
96 MODULE_DESCRIPTION("Nokia composite gadget driver for N900");
97 MODULE_AUTHOR("Felipe Balbi");
98 MODULE_LICENSE("GPL");
100 /*-------------------------------------------------------------------------*/
102 static u8 hostaddr
[ETH_ALEN
];
111 static unsigned char tty_lines
[TTY_PORTS_MAX
];
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
, tty_lines
[TTY_PORT_OBEX0
]);
123 printk(KERN_DEBUG
"could not bind obex config %d\n", 0);
125 status
= obex_bind_config(c
, tty_lines
[TTY_PORT_OBEX1
]);
127 printk(KERN_DEBUG
"could not bind obex config %d\n", 0);
129 status
= acm_bind_config(c
, tty_lines
[TTY_PORT_ACM
]);
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
= {
141 .label
= "Bus Powered",
142 .bConfigurationValue
= 1,
143 /* .iConfiguration = DYNAMIC */
144 .bmAttributes
= USB_CONFIG_ATT_ONE
,
148 static struct usb_configuration nokia_config_100ma_driver
= {
149 .label
= "Self Powered",
150 .bConfigurationValue
= 2,
151 /* .iConfiguration = DYNAMIC */
152 .bmAttributes
= USB_CONFIG_ATT_ONE
| USB_CONFIG_ATT_SELFPOWER
,
156 static int __init
nokia_bind(struct usb_composite_dev
*cdev
)
158 struct usb_gadget
*gadget
= cdev
->gadget
;
162 status
= gphonet_setup(cdev
->gadget
);
166 for (cur_line
= 0; cur_line
< TTY_PORTS_MAX
; cur_line
++) {
167 status
= gserial_alloc_line(&tty_lines
[cur_line
]);
172 status
= gether_setup(cdev
->gadget
, hostaddr
);
176 status
= usb_string_ids_tab(cdev
, strings_dev
);
179 device_desc
.iManufacturer
= strings_dev
[USB_GADGET_MANUFACTURER_IDX
].id
;
180 device_desc
.iProduct
= strings_dev
[USB_GADGET_PRODUCT_IDX
].id
;
181 status
= strings_dev
[STRING_DESCRIPTION_IDX
].id
;
182 nokia_config_500ma_driver
.iConfiguration
= status
;
183 nokia_config_100ma_driver
.iConfiguration
= status
;
185 if (!gadget_supports_altsettings(gadget
))
188 /* finally register the configuration */
189 status
= usb_add_config(cdev
, &nokia_config_500ma_driver
,
194 status
= usb_add_config(cdev
, &nokia_config_100ma_driver
,
199 usb_composite_overwrite_options(cdev
, &coverwrite
);
200 dev_info(&gadget
->dev
, "%s\n", NOKIA_LONG_NAME
);
208 while (cur_line
>= 0)
209 gserial_free_line(tty_lines
[cur_line
--]);
216 static int __exit
nokia_unbind(struct usb_composite_dev
*cdev
)
222 for (i
= 0; i
< TTY_PORTS_MAX
; i
++)
223 gserial_free_line(tty_lines
[i
]);
230 static __refdata
struct usb_composite_driver nokia_driver
= {
233 .strings
= dev_strings
,
234 .max_speed
= USB_SPEED_HIGH
,
236 .unbind
= __exit_p(nokia_unbind
),
239 static int __init
nokia_init(void)
241 return usb_composite_probe(&nokia_driver
);
243 module_init(nokia_init
);
245 static void __exit
nokia_cleanup(void)
247 usb_composite_unregister(&nokia_driver
);
249 module_exit(nokia_cleanup
);