visor.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /*
  2. * USB HandSpring Visor, Palm m50x, and Sony Clie driver
  3. * (supports all of the Palm OS USB devices)
  4. *
  5. * Copyright (C) 1999 - 2004
  6. * Greg Kroah-Hartman (greg@kroah.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * See Documentation/usb/usb-serial.txt for more information on using this driver
  14. *
  15. * (06/03/2003) Judd Montgomery <judd at jpilot.org>
  16. * Added support for module parameter options for untested/unknown
  17. * devices.
  18. *
  19. * (03/09/2003) gkh
  20. * Added support for the Sony Clie NZ90V device. Thanks to Martin Brachtl
  21. * <brachtl@redgrep.cz> for the information.
  22. *
  23. * (03/05/2003) gkh
  24. * Think Treo support is now working.
  25. *
  26. * (04/03/2002) gkh
  27. * Added support for the Sony OS 4.1 devices. Thanks to Hiroyuki ARAKI
  28. * <hiro@zob.ne.jp> for the information.
  29. *
  30. * (03/27/2002) gkh
  31. * Removed assumptions that port->tty was always valid (is not true
  32. * for usb serial console devices.)
  33. *
  34. * (03/23/2002) gkh
  35. * Added support for the Palm i705 device, thanks to Thomas Riemer
  36. * <tom@netmech.com> for the information.
  37. *
  38. * (03/21/2002) gkh
  39. * Added support for the Palm m130 device, thanks to Udo Eisenbarth
  40. * <udo.eisenbarth@web.de> for the information.
  41. *
  42. * (02/27/2002) gkh
  43. * Reworked the urb handling logic. We have no more pool, but dynamically
  44. * allocate the urb and the transfer buffer on the fly. In testing this
  45. * does not incure any measurable overhead. This also relies on the fact
  46. * that we have proper reference counting logic for urbs.
  47. *
  48. * (02/21/2002) SilaS
  49. * Added initial support for the Palm m515 devices.
  50. *
  51. * (02/14/2002) gkh
  52. * Added support for the Clie S-360 device.
  53. *
  54. * (12/18/2001) gkh
  55. * Added better Clie support for 3.5 devices. Thanks to Geoffrey Levand
  56. * for the patch.
  57. *
  58. * (11/11/2001) gkh
  59. * Added support for the m125 devices, and added check to prevent oopses
  60. * for Clié devices that lie about the number of ports they have.
  61. *
  62. * (08/30/2001) gkh
  63. * Added support for the Clie devices, both the 3.5 and 4.0 os versions.
  64. * Many thanks to Daniel Burke, and Bryan Payne for helping with this.
  65. *
  66. * (08/23/2001) gkh
  67. * fixed a few potential bugs pointed out by Oliver Neukum.
  68. *
  69. * (05/30/2001) gkh
  70. * switched from using spinlock to a semaphore, which fixes lots of problems.
  71. *
  72. * (05/28/2000) gkh
  73. * Added initial support for the Palm m500 and Palm m505 devices.
  74. *
  75. * (04/08/2001) gb
  76. * Identify version on module load.
  77. *
  78. * (01/21/2000) gkh
  79. * Added write_room and chars_in_buffer, as they were previously using the
  80. * generic driver versions which is all wrong now that we are using an urb
  81. * pool. Thanks to Wolfgang Grandegger for pointing this out to me.
  82. * Removed count assignment in the write function, which was not needed anymore
  83. * either. Thanks to Al Borchers for pointing this out.
  84. *
  85. * (12/12/2000) gkh
  86. * Moved MOD_DEC to end of visor_close to be nicer, as the final write
  87. * message can sleep.
  88. *
  89. * (11/12/2000) gkh
  90. * Fixed bug with data being dropped on the floor by forcing tty->low_latency
  91. * to be on. Hopefully this fixes the OHCI issue!
  92. *
  93. * (11/01/2000) Adam J. Richter
  94. * usb_device_id table support
  95. *
  96. * (10/05/2000) gkh
  97. * Fixed bug with urb->dev not being set properly, now that the usb
  98. * core needs it.
  99. *
  100. * (09/11/2000) gkh
  101. * Got rid of always calling kmalloc for every urb we wrote out to the
  102. * device.
  103. * Added visor_read_callback so we can keep track of bytes in and out for
  104. * those people who like to know the speed of their device.
  105. * Removed DEBUG #ifdefs with call to usb_serial_debug_data
  106. *
  107. * (09/06/2000) gkh
  108. * Fixed oops in visor_exit. Need to uncomment usb_unlink_urb call _after_
  109. * the host controller drivers set urb->dev = NULL when the urb is finished.
  110. *
  111. * (08/28/2000) gkh
  112. * Added locks for SMP safeness.
  113. *
  114. * (08/08/2000) gkh
  115. * Fixed endian problem in visor_startup.
  116. * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
  117. * than once.
  118. *
  119. * (07/23/2000) gkh
  120. * Added pool of write urbs to speed up transfers to the visor.
  121. *
  122. * (07/19/2000) gkh
  123. * Added module_init and module_exit functions to handle the fact that this
  124. * driver is a loadable module now.
  125. *
  126. * (07/03/2000) gkh
  127. * Added visor_set_ioctl and visor_set_termios functions (they don't do much
  128. * of anything, but are good for debugging.)
  129. *
  130. * (06/25/2000) gkh
  131. * Fixed bug in visor_unthrottle that should help with the disconnect in PPP
  132. * bug that people have been reporting.
  133. *
  134. * (06/23/2000) gkh
  135. * Cleaned up debugging statements in a quest to find UHCI timeout bug.
  136. *
  137. * (04/27/2000) Ryan VanderBijl
  138. * Fixed memory leak in visor_close
  139. *
  140. * (03/26/2000) gkh
  141. * Split driver up into device specific pieces.
  142. *
  143. */
  144. #include <linux/config.h>
  145. #include <linux/kernel.h>
  146. #include <linux/errno.h>
  147. #include <linux/init.h>
  148. #include <linux/slab.h>
  149. #include <linux/tty.h>
  150. #include <linux/tty_driver.h>
  151. #include <linux/tty_flip.h>
  152. #include <linux/module.h>
  153. #include <linux/moduleparam.h>
  154. #include <linux/spinlock.h>
  155. #include <asm/uaccess.h>
  156. #include <linux/usb.h>
  157. #include "usb-serial.h"
  158. #include "visor.h"
  159. /*
  160. * Version Information
  161. */
  162. #define DRIVER_VERSION "v2.1"
  163. #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
  164. #define DRIVER_DESC "USB HandSpring Visor / Palm OS driver"
  165. /* function prototypes for a handspring visor */
  166. static int visor_open (struct usb_serial_port *port, struct file *filp);
  167. static void visor_close (struct usb_serial_port *port, struct file *filp);
  168. static int visor_write (struct usb_serial_port *port, const unsigned char *buf, int count);
  169. static int visor_write_room (struct usb_serial_port *port);
  170. static int visor_chars_in_buffer (struct usb_serial_port *port);
  171. static void visor_throttle (struct usb_serial_port *port);
  172. static void visor_unthrottle (struct usb_serial_port *port);
  173. static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id);
  174. static int visor_calc_num_ports(struct usb_serial *serial);
  175. static void visor_shutdown (struct usb_serial *serial);
  176. static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
  177. static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios);
  178. static void visor_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
  179. static void visor_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
  180. static void visor_read_int_callback (struct urb *urb, struct pt_regs *regs);
  181. static int clie_3_5_startup (struct usb_serial *serial);
  182. static int treo_attach (struct usb_serial *serial);
  183. static int clie_5_attach (struct usb_serial *serial);
  184. static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id);
  185. static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id);
  186. /* Parameters that may be passed into the module. */
  187. static int debug;
  188. static __u16 vendor;
  189. static __u16 product;
  190. static struct usb_device_id id_table [] = {
  191. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID),
  192. .driver_info = (kernel_ulong_t)&palm_os_3_probe },
  193. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID),
  194. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  195. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID),
  196. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  197. { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID),
  198. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  199. { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID),
  200. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  201. { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID),
  202. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  203. { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID),
  204. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  205. { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID),
  206. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  207. { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID),
  208. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  209. { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID),
  210. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  211. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID),
  212. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  213. { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650),
  214. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  215. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID),
  216. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  217. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE31_ID),
  218. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  219. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID),
  220. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  221. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID),
  222. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  223. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID),
  224. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  225. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID),
  226. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  227. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID),
  228. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  229. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID),
  230. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  231. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID),
  232. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  233. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID),
  234. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  235. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID),
  236. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  237. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID),
  238. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  239. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID),
  240. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  241. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID),
  242. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  243. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID),
  244. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  245. { }, /* optional parameter entry */
  246. { } /* Terminating entry */
  247. };
  248. static struct usb_device_id clie_id_5_table [] = {
  249. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID),
  250. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  251. { }, /* optional parameter entry */
  252. { } /* Terminating entry */
  253. };
  254. static struct usb_device_id clie_id_3_5_table [] = {
  255. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  256. { } /* Terminating entry */
  257. };
  258. static struct usb_device_id id_table_combined [] = {
  259. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
  260. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) },
  261. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) },
  262. { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
  263. { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
  264. { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
  265. { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
  266. { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID) },
  267. { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
  268. { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
  269. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID) },
  270. { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650) },
  271. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID) },
  272. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE31_ID) },
  273. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID) },
  274. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  275. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
  276. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
  277. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID) },
  278. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID) },
  279. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID) },
  280. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID) },
  281. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID) },
  282. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID) },
  283. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID) },
  284. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID) },
  285. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID) },
  286. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID) },
  287. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID) },
  288. { }, /* optional parameter entry */
  289. { } /* Terminating entry */
  290. };
  291. MODULE_DEVICE_TABLE (usb, id_table_combined);
  292. static struct usb_driver visor_driver = {
  293. .owner = THIS_MODULE,
  294. .name = "visor",
  295. .probe = usb_serial_probe,
  296. .disconnect = usb_serial_disconnect,
  297. .id_table = id_table_combined,
  298. };
  299. /* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */
  300. static struct usb_serial_device_type handspring_device = {
  301. .owner = THIS_MODULE,
  302. .name = "Handspring Visor / Palm OS",
  303. .short_name = "visor",
  304. .id_table = id_table,
  305. .num_interrupt_in = NUM_DONT_CARE,
  306. .num_bulk_in = 2,
  307. .num_bulk_out = 2,
  308. .num_ports = 2,
  309. .open = visor_open,
  310. .close = visor_close,
  311. .throttle = visor_throttle,
  312. .unthrottle = visor_unthrottle,
  313. .attach = treo_attach,
  314. .probe = visor_probe,
  315. .calc_num_ports = visor_calc_num_ports,
  316. .shutdown = visor_shutdown,
  317. .ioctl = visor_ioctl,
  318. .set_termios = visor_set_termios,
  319. .write = visor_write,
  320. .write_room = visor_write_room,
  321. .chars_in_buffer = visor_chars_in_buffer,
  322. .write_bulk_callback = visor_write_bulk_callback,
  323. .read_bulk_callback = visor_read_bulk_callback,
  324. .read_int_callback = visor_read_int_callback,
  325. };
  326. /* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */
  327. static struct usb_serial_device_type clie_5_device = {
  328. .owner = THIS_MODULE,
  329. .name = "Sony Clie 5.0",
  330. .short_name = "clie_5",
  331. .id_table = clie_id_5_table,
  332. .num_interrupt_in = NUM_DONT_CARE,
  333. .num_bulk_in = 2,
  334. .num_bulk_out = 2,
  335. .num_ports = 2,
  336. .open = visor_open,
  337. .close = visor_close,
  338. .throttle = visor_throttle,
  339. .unthrottle = visor_unthrottle,
  340. .attach = clie_5_attach,
  341. .probe = visor_probe,
  342. .calc_num_ports = visor_calc_num_ports,
  343. .shutdown = visor_shutdown,
  344. .ioctl = visor_ioctl,
  345. .set_termios = visor_set_termios,
  346. .write = visor_write,
  347. .write_room = visor_write_room,
  348. .chars_in_buffer = visor_chars_in_buffer,
  349. .write_bulk_callback = visor_write_bulk_callback,
  350. .read_bulk_callback = visor_read_bulk_callback,
  351. .read_int_callback = visor_read_int_callback,
  352. };
  353. /* device info for the Sony Clie OS version 3.5 */
  354. static struct usb_serial_device_type clie_3_5_device = {
  355. .owner = THIS_MODULE,
  356. .name = "Sony Clie 3.5",
  357. .short_name = "clie_3.5",
  358. .id_table = clie_id_3_5_table,
  359. .num_interrupt_in = 0,
  360. .num_bulk_in = 1,
  361. .num_bulk_out = 1,
  362. .num_ports = 1,
  363. .open = visor_open,
  364. .close = visor_close,
  365. .throttle = visor_throttle,
  366. .unthrottle = visor_unthrottle,
  367. .attach = clie_3_5_startup,
  368. .ioctl = visor_ioctl,
  369. .set_termios = visor_set_termios,
  370. .write = visor_write,
  371. .write_room = visor_write_room,
  372. .chars_in_buffer = visor_chars_in_buffer,
  373. .write_bulk_callback = visor_write_bulk_callback,
  374. .read_bulk_callback = visor_read_bulk_callback,
  375. };
  376. struct visor_private {
  377. spinlock_t lock;
  378. int bytes_in;
  379. int bytes_out;
  380. int outstanding_urbs;
  381. int throttled;
  382. };
  383. /* number of outstanding urbs to prevent userspace DoS from happening */
  384. #define URB_UPPER_LIMIT 42
  385. static int stats;
  386. /******************************************************************************
  387. * Handspring Visor specific driver functions
  388. ******************************************************************************/
  389. static int visor_open (struct usb_serial_port *port, struct file *filp)
  390. {
  391. struct usb_serial *serial = port->serial;
  392. struct visor_private *priv = usb_get_serial_port_data(port);
  393. unsigned long flags;
  394. int result = 0;
  395. dbg("%s - port %d", __FUNCTION__, port->number);
  396. if (!port->read_urb) {
  397. /* this is needed for some brain dead Sony devices */
  398. dev_err(&port->dev, "Device lied about number of ports, please use a lower one.\n");
  399. return -ENODEV;
  400. }
  401. spin_lock_irqsave(&priv->lock, flags);
  402. priv->bytes_in = 0;
  403. priv->bytes_out = 0;
  404. priv->outstanding_urbs = 0;
  405. priv->throttled = 0;
  406. spin_unlock_irqrestore(&priv->lock, flags);
  407. /*
  408. * Force low_latency on so that our tty_push actually forces the data
  409. * through, otherwise it is scheduled, and with high data rates (like
  410. * with OHCI) data can get lost.
  411. */
  412. if (port->tty)
  413. port->tty->low_latency = 1;
  414. /* Start reading from the device */
  415. usb_fill_bulk_urb (port->read_urb, serial->dev,
  416. usb_rcvbulkpipe (serial->dev,
  417. port->bulk_in_endpointAddress),
  418. port->read_urb->transfer_buffer,
  419. port->read_urb->transfer_buffer_length,
  420. visor_read_bulk_callback, port);
  421. result = usb_submit_urb(port->read_urb, GFP_KERNEL);
  422. if (result) {
  423. dev_err(&port->dev, "%s - failed submitting read urb, error %d\n",
  424. __FUNCTION__, result);
  425. goto exit;
  426. }
  427. if (port->interrupt_in_urb) {
  428. dbg("%s - adding interrupt input for treo", __FUNCTION__);
  429. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  430. if (result)
  431. dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n",
  432. __FUNCTION__, result);
  433. }
  434. exit:
  435. return result;
  436. }
  437. static void visor_close (struct usb_serial_port *port, struct file * filp)
  438. {
  439. struct visor_private *priv = usb_get_serial_port_data(port);
  440. unsigned char *transfer_buffer;
  441. dbg("%s - port %d", __FUNCTION__, port->number);
  442. /* shutdown our urbs */
  443. usb_kill_urb(port->read_urb);
  444. if (port->interrupt_in_urb)
  445. usb_kill_urb(port->interrupt_in_urb);
  446. /* Try to send shutdown message, if the device is gone, this will just fail. */
  447. transfer_buffer = kmalloc (0x12, GFP_KERNEL);
  448. if (transfer_buffer) {
  449. usb_control_msg (port->serial->dev,
  450. usb_rcvctrlpipe(port->serial->dev, 0),
  451. VISOR_CLOSE_NOTIFICATION, 0xc2,
  452. 0x0000, 0x0000,
  453. transfer_buffer, 0x12, 300);
  454. kfree (transfer_buffer);
  455. }
  456. if (stats)
  457. dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n",
  458. priv->bytes_in, priv->bytes_out);
  459. }
  460. static int visor_write (struct usb_serial_port *port, const unsigned char *buf, int count)
  461. {
  462. struct visor_private *priv = usb_get_serial_port_data(port);
  463. struct usb_serial *serial = port->serial;
  464. struct urb *urb;
  465. unsigned char *buffer;
  466. unsigned long flags;
  467. int status;
  468. dbg("%s - port %d", __FUNCTION__, port->number);
  469. spin_lock_irqsave(&priv->lock, flags);
  470. if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
  471. spin_unlock_irqrestore(&priv->lock, flags);
  472. dbg("%s - write limit hit\n", __FUNCTION__);
  473. return 0;
  474. }
  475. spin_unlock_irqrestore(&priv->lock, flags);
  476. buffer = kmalloc (count, GFP_ATOMIC);
  477. if (!buffer) {
  478. dev_err(&port->dev, "out of memory\n");
  479. return -ENOMEM;
  480. }
  481. urb = usb_alloc_urb(0, GFP_ATOMIC);
  482. if (!urb) {
  483. dev_err(&port->dev, "no more free urbs\n");
  484. kfree (buffer);
  485. return -ENOMEM;
  486. }
  487. memcpy (buffer, buf, count);
  488. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer);
  489. usb_fill_bulk_urb (urb, serial->dev,
  490. usb_sndbulkpipe (serial->dev,
  491. port->bulk_out_endpointAddress),
  492. buffer, count,
  493. visor_write_bulk_callback, port);
  494. /* send it down the pipe */
  495. status = usb_submit_urb(urb, GFP_ATOMIC);
  496. if (status) {
  497. dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n",
  498. __FUNCTION__, status);
  499. count = status;
  500. kfree (buffer);
  501. } else {
  502. spin_lock_irqsave(&priv->lock, flags);
  503. ++priv->outstanding_urbs;
  504. priv->bytes_out += count;
  505. spin_unlock_irqrestore(&priv->lock, flags);
  506. }
  507. /* we are done with this urb, so let the host driver
  508. * really free it when it is finished with it */
  509. usb_free_urb (urb);
  510. return count;
  511. }
  512. static int visor_write_room (struct usb_serial_port *port)
  513. {
  514. dbg("%s - port %d", __FUNCTION__, port->number);
  515. /*
  516. * We really can take anything the user throws at us
  517. * but let's pick a nice big number to tell the tty
  518. * layer that we have lots of free space
  519. */
  520. return 2048;
  521. }
  522. static int visor_chars_in_buffer (struct usb_serial_port *port)
  523. {
  524. dbg("%s - port %d", __FUNCTION__, port->number);
  525. /*
  526. * We can't really account for how much data we
  527. * have sent out, but hasn't made it through to the
  528. * device, so just tell the tty layer that everything
  529. * is flushed.
  530. */
  531. return 0;
  532. }
  533. static void visor_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
  534. {
  535. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  536. struct visor_private *priv = usb_get_serial_port_data(port);
  537. unsigned long flags;
  538. /* free up the transfer buffer, as usb_free_urb() does not do this */
  539. kfree (urb->transfer_buffer);
  540. dbg("%s - port %d", __FUNCTION__, port->number);
  541. if (urb->status)
  542. dbg("%s - nonzero write bulk status received: %d",
  543. __FUNCTION__, urb->status);
  544. spin_lock_irqsave(&priv->lock, flags);
  545. --priv->outstanding_urbs;
  546. spin_unlock_irqrestore(&priv->lock, flags);
  547. schedule_work(&port->work);
  548. }
  549. static void visor_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
  550. {
  551. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  552. struct visor_private *priv = usb_get_serial_port_data(port);
  553. unsigned char *data = urb->transfer_buffer;
  554. struct tty_struct *tty;
  555. unsigned long flags;
  556. int i;
  557. int throttled;
  558. int result;
  559. dbg("%s - port %d", __FUNCTION__, port->number);
  560. if (urb->status) {
  561. dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
  562. return;
  563. }
  564. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
  565. tty = port->tty;
  566. if (tty && urb->actual_length) {
  567. for (i = 0; i < urb->actual_length ; ++i) {
  568. /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
  569. if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
  570. tty_flip_buffer_push(tty);
  571. }
  572. /* this doesn't actually push the data through unless tty->low_latency is set */
  573. tty_insert_flip_char(tty, data[i], 0);
  574. }
  575. tty_flip_buffer_push(tty);
  576. }
  577. spin_lock_irqsave(&priv->lock, flags);
  578. priv->bytes_in += urb->actual_length;
  579. throttled = priv->throttled;
  580. spin_unlock_irqrestore(&priv->lock, flags);
  581. /* Continue trying to always read if we should */
  582. if (!throttled) {
  583. usb_fill_bulk_urb (port->read_urb, port->serial->dev,
  584. usb_rcvbulkpipe(port->serial->dev,
  585. port->bulk_in_endpointAddress),
  586. port->read_urb->transfer_buffer,
  587. port->read_urb->transfer_buffer_length,
  588. visor_read_bulk_callback, port);
  589. result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
  590. if (result)
  591. dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
  592. }
  593. return;
  594. }
  595. static void visor_read_int_callback (struct urb *urb, struct pt_regs *regs)
  596. {
  597. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  598. int result;
  599. switch (urb->status) {
  600. case 0:
  601. /* success */
  602. break;
  603. case -ECONNRESET:
  604. case -ENOENT:
  605. case -ESHUTDOWN:
  606. /* this urb is terminated, clean up */
  607. dbg("%s - urb shutting down with status: %d",
  608. __FUNCTION__, urb->status);
  609. return;
  610. default:
  611. dbg("%s - nonzero urb status received: %d",
  612. __FUNCTION__, urb->status);
  613. goto exit;
  614. }
  615. /*
  616. * This information is still unknown what it can be used for.
  617. * If anyone has an idea, please let the author know...
  618. *
  619. * Rumor has it this endpoint is used to notify when data
  620. * is ready to be read from the bulk ones.
  621. */
  622. usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
  623. urb->actual_length, urb->transfer_buffer);
  624. exit:
  625. result = usb_submit_urb (urb, GFP_ATOMIC);
  626. if (result)
  627. dev_err(&urb->dev->dev, "%s - Error %d submitting interrupt urb\n",
  628. __FUNCTION__, result);
  629. }
  630. static void visor_throttle (struct usb_serial_port *port)
  631. {
  632. struct visor_private *priv = usb_get_serial_port_data(port);
  633. unsigned long flags;
  634. dbg("%s - port %d", __FUNCTION__, port->number);
  635. spin_lock_irqsave(&priv->lock, flags);
  636. priv->throttled = 1;
  637. spin_unlock_irqrestore(&priv->lock, flags);
  638. }
  639. static void visor_unthrottle (struct usb_serial_port *port)
  640. {
  641. struct visor_private *priv = usb_get_serial_port_data(port);
  642. unsigned long flags;
  643. int result;
  644. dbg("%s - port %d", __FUNCTION__, port->number);
  645. spin_lock_irqsave(&priv->lock, flags);
  646. priv->throttled = 0;
  647. spin_unlock_irqrestore(&priv->lock, flags);
  648. port->read_urb->dev = port->serial->dev;
  649. result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
  650. if (result)
  651. dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
  652. }
  653. static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id)
  654. {
  655. struct device *dev = &serial->dev->dev;
  656. struct visor_connection_info *connection_info;
  657. unsigned char *transfer_buffer;
  658. char *string;
  659. int retval = 0;
  660. int i;
  661. int num_ports = 0;
  662. dbg("%s", __FUNCTION__);
  663. transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL);
  664. if (!transfer_buffer) {
  665. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __FUNCTION__,
  666. sizeof(*connection_info));
  667. return -ENOMEM;
  668. }
  669. /* send a get connection info request */
  670. retval = usb_control_msg (serial->dev,
  671. usb_rcvctrlpipe(serial->dev, 0),
  672. VISOR_GET_CONNECTION_INFORMATION,
  673. 0xc2, 0x0000, 0x0000, transfer_buffer,
  674. sizeof(*connection_info), 300);
  675. if (retval < 0) {
  676. dev_err(dev, "%s - error %d getting connection information\n",
  677. __FUNCTION__, retval);
  678. goto exit;
  679. }
  680. if (retval == sizeof(*connection_info)) {
  681. connection_info = (struct visor_connection_info *)transfer_buffer;
  682. num_ports = le16_to_cpu(connection_info->num_ports);
  683. for (i = 0; i < num_ports; ++i) {
  684. switch (connection_info->connections[i].port_function_id) {
  685. case VISOR_FUNCTION_GENERIC:
  686. string = "Generic";
  687. break;
  688. case VISOR_FUNCTION_DEBUGGER:
  689. string = "Debugger";
  690. break;
  691. case VISOR_FUNCTION_HOTSYNC:
  692. string = "HotSync";
  693. break;
  694. case VISOR_FUNCTION_CONSOLE:
  695. string = "Console";
  696. break;
  697. case VISOR_FUNCTION_REMOTE_FILE_SYS:
  698. string = "Remote File System";
  699. break;
  700. default:
  701. string = "unknown";
  702. break;
  703. }
  704. dev_info(dev, "%s: port %d, is for %s use\n",
  705. serial->type->name,
  706. connection_info->connections[i].port, string);
  707. }
  708. }
  709. /*
  710. * Handle devices that report invalid stuff here.
  711. */
  712. if (num_ports == 0 || num_ports > 2) {
  713. dev_warn (dev, "%s: No valid connect info available\n",
  714. serial->type->name);
  715. num_ports = 2;
  716. }
  717. dev_info(dev, "%s: Number of ports: %d\n", serial->type->name,
  718. num_ports);
  719. /*
  720. * save off our num_ports info so that we can use it in the
  721. * calc_num_ports callback
  722. */
  723. usb_set_serial_data(serial, (void *)(long)num_ports);
  724. /* ask for the number of bytes available, but ignore the response as it is broken */
  725. retval = usb_control_msg (serial->dev,
  726. usb_rcvctrlpipe(serial->dev, 0),
  727. VISOR_REQUEST_BYTES_AVAILABLE,
  728. 0xc2, 0x0000, 0x0005, transfer_buffer,
  729. 0x02, 300);
  730. if (retval < 0)
  731. dev_err(dev, "%s - error %d getting bytes available request\n",
  732. __FUNCTION__, retval);
  733. retval = 0;
  734. exit:
  735. kfree (transfer_buffer);
  736. return retval;
  737. }
  738. static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id)
  739. {
  740. struct device *dev = &serial->dev->dev;
  741. struct palm_ext_connection_info *connection_info;
  742. unsigned char *transfer_buffer;
  743. int retval;
  744. dbg("%s", __FUNCTION__);
  745. transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL);
  746. if (!transfer_buffer) {
  747. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __FUNCTION__,
  748. sizeof(*connection_info));
  749. return -ENOMEM;
  750. }
  751. retval = usb_control_msg (serial->dev,
  752. usb_rcvctrlpipe(serial->dev, 0),
  753. PALM_GET_EXT_CONNECTION_INFORMATION,
  754. 0xc2, 0x0000, 0x0000, transfer_buffer,
  755. sizeof (*connection_info), 300);
  756. if (retval < 0)
  757. dev_err(dev, "%s - error %d getting connection info\n",
  758. __FUNCTION__, retval);
  759. else
  760. usb_serial_debug_data(debug, &serial->dev->dev, __FUNCTION__,
  761. retval, transfer_buffer);
  762. kfree (transfer_buffer);
  763. return 0;
  764. }
  765. static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id)
  766. {
  767. int retval = 0;
  768. int (*startup) (struct usb_serial *serial, const struct usb_device_id *id);
  769. dbg("%s", __FUNCTION__);
  770. if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
  771. err("active config #%d != 1 ??",
  772. serial->dev->actconfig->desc.bConfigurationValue);
  773. return -ENODEV;
  774. }
  775. if (id->driver_info) {
  776. startup = (void *)id->driver_info;
  777. retval = startup(serial, id);
  778. }
  779. return retval;
  780. }
  781. static int visor_calc_num_ports (struct usb_serial *serial)
  782. {
  783. int num_ports = (int)(long)(usb_get_serial_data(serial));
  784. if (num_ports)
  785. usb_set_serial_data(serial, NULL);
  786. return num_ports;
  787. }
  788. static int generic_startup(struct usb_serial *serial)
  789. {
  790. struct visor_private *priv;
  791. int i;
  792. for (i = 0; i < serial->num_ports; ++i) {
  793. priv = kmalloc (sizeof(*priv), GFP_KERNEL);
  794. if (!priv)
  795. return -ENOMEM;
  796. memset (priv, 0x00, sizeof(*priv));
  797. spin_lock_init(&priv->lock);
  798. usb_set_serial_port_data(serial->port[i], priv);
  799. }
  800. return 0;
  801. }
  802. static int clie_3_5_startup (struct usb_serial *serial)
  803. {
  804. struct device *dev = &serial->dev->dev;
  805. int result;
  806. u8 data;
  807. dbg("%s", __FUNCTION__);
  808. /*
  809. * Note that PEG-300 series devices expect the following two calls.
  810. */
  811. /* get the config number */
  812. result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  813. USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
  814. 0, 0, &data, 1, 3000);
  815. if (result < 0) {
  816. dev_err(dev, "%s: get config number failed: %d\n", __FUNCTION__, result);
  817. return result;
  818. }
  819. if (result != 1) {
  820. dev_err(dev, "%s: get config number bad return length: %d\n", __FUNCTION__, result);
  821. return -EIO;
  822. }
  823. /* get the interface number */
  824. result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  825. USB_REQ_GET_INTERFACE,
  826. USB_DIR_IN | USB_RECIP_INTERFACE,
  827. 0, 0, &data, 1, 3000);
  828. if (result < 0) {
  829. dev_err(dev, "%s: get interface number failed: %d\n", __FUNCTION__, result);
  830. return result;
  831. }
  832. if (result != 1) {
  833. dev_err(dev, "%s: get interface number bad return length: %d\n", __FUNCTION__, result);
  834. return -EIO;
  835. }
  836. return generic_startup(serial);
  837. }
  838. static int treo_attach (struct usb_serial *serial)
  839. {
  840. struct usb_serial_port *swap_port;
  841. /* Only do this endpoint hack for the Handspring devices with
  842. * interrupt in endpoints, which for now are the Treo devices. */
  843. if (!((le16_to_cpu(serial->dev->descriptor.idVendor) == HANDSPRING_VENDOR_ID) ||
  844. (le16_to_cpu(serial->dev->descriptor.idVendor) == KYOCERA_VENDOR_ID)) ||
  845. (serial->num_interrupt_in == 0))
  846. goto generic_startup;
  847. dbg("%s", __FUNCTION__);
  848. /*
  849. * It appears that Treos and Kyoceras want to use the
  850. * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint,
  851. * so let's swap the 1st and 2nd bulk in and interrupt endpoints.
  852. * Note that swapping the bulk out endpoints would break lots of
  853. * apps that want to communicate on the second port.
  854. */
  855. #define COPY_PORT(dest, src) \
  856. dest->read_urb = src->read_urb; \
  857. dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress; \
  858. dest->bulk_in_buffer = src->bulk_in_buffer; \
  859. dest->interrupt_in_urb = src->interrupt_in_urb; \
  860. dest->interrupt_in_endpointAddress = src->interrupt_in_endpointAddress; \
  861. dest->interrupt_in_buffer = src->interrupt_in_buffer;
  862. swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL);
  863. if (!swap_port)
  864. return -ENOMEM;
  865. COPY_PORT(swap_port, serial->port[0]);
  866. COPY_PORT(serial->port[0], serial->port[1]);
  867. COPY_PORT(serial->port[1], swap_port);
  868. kfree(swap_port);
  869. generic_startup:
  870. return generic_startup(serial);
  871. }
  872. static int clie_5_attach (struct usb_serial *serial)
  873. {
  874. dbg("%s", __FUNCTION__);
  875. /* TH55 registers 2 ports.
  876. Communication in from the UX50/TH55 uses bulk_in_endpointAddress from port 0
  877. Communication out to the UX50/TH55 uses bulk_out_endpointAddress from port 1
  878. Lets do a quick and dirty mapping
  879. */
  880. /* some sanity check */
  881. if (serial->num_ports < 2)
  882. return -1;
  883. /* port 0 now uses the modified endpoint Address */
  884. serial->port[0]->bulk_out_endpointAddress = serial->port[1]->bulk_out_endpointAddress;
  885. return generic_startup(serial);
  886. }
  887. static void visor_shutdown (struct usb_serial *serial)
  888. {
  889. dbg("%s", __FUNCTION__);
  890. }
  891. static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
  892. {
  893. dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
  894. return -ENOIOCTLCMD;
  895. }
  896. /* This function is all nice and good, but we don't change anything based on it :) */
  897. static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios)
  898. {
  899. unsigned int cflag;
  900. dbg("%s - port %d", __FUNCTION__, port->number);
  901. if ((!port->tty) || (!port->tty->termios)) {
  902. dbg("%s - no tty structures", __FUNCTION__);
  903. return;
  904. }
  905. cflag = port->tty->termios->c_cflag;
  906. /* check that they really want us to change something */
  907. if (old_termios) {
  908. if ((cflag == old_termios->c_cflag) &&
  909. (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
  910. dbg("%s - nothing to change...", __FUNCTION__);
  911. return;
  912. }
  913. }
  914. /* get the byte size */
  915. switch (cflag & CSIZE) {
  916. case CS5: dbg("%s - data bits = 5", __FUNCTION__); break;
  917. case CS6: dbg("%s - data bits = 6", __FUNCTION__); break;
  918. case CS7: dbg("%s - data bits = 7", __FUNCTION__); break;
  919. default:
  920. case CS8: dbg("%s - data bits = 8", __FUNCTION__); break;
  921. }
  922. /* determine the parity */
  923. if (cflag & PARENB)
  924. if (cflag & PARODD)
  925. dbg("%s - parity = odd", __FUNCTION__);
  926. else
  927. dbg("%s - parity = even", __FUNCTION__);
  928. else
  929. dbg("%s - parity = none", __FUNCTION__);
  930. /* figure out the stop bits requested */
  931. if (cflag & CSTOPB)
  932. dbg("%s - stop bits = 2", __FUNCTION__);
  933. else
  934. dbg("%s - stop bits = 1", __FUNCTION__);
  935. /* figure out the flow control settings */
  936. if (cflag & CRTSCTS)
  937. dbg("%s - RTS/CTS is enabled", __FUNCTION__);
  938. else
  939. dbg("%s - RTS/CTS is disabled", __FUNCTION__);
  940. /* determine software flow control */
  941. if (I_IXOFF(port->tty))
  942. dbg("%s - XON/XOFF is enabled, XON = %2x, XOFF = %2x",
  943. __FUNCTION__, START_CHAR(port->tty), STOP_CHAR(port->tty));
  944. else
  945. dbg("%s - XON/XOFF is disabled", __FUNCTION__);
  946. /* get the baud rate wanted */
  947. dbg("%s - baud rate = %d", __FUNCTION__, tty_get_baud_rate(port->tty));
  948. return;
  949. }
  950. static int __init visor_init (void)
  951. {
  952. int i, retval;
  953. /* Only if parameters were passed to us */
  954. if ((vendor>0) && (product>0)) {
  955. struct usb_device_id usb_dev_temp[]=
  956. {{USB_DEVICE(vendor, product),
  957. .driver_info = (kernel_ulong_t)&palm_os_4_probe }};
  958. /* Find the last entry in id_table */
  959. for (i=0; ; i++) {
  960. if (id_table[i].idVendor==0) {
  961. id_table[i] = usb_dev_temp[0];
  962. break;
  963. }
  964. }
  965. /* Find the last entry in id_table_combined */
  966. for (i=0; ; i++) {
  967. if (id_table_combined[i].idVendor==0) {
  968. id_table_combined[i] = usb_dev_temp[0];
  969. break;
  970. }
  971. }
  972. info("Untested USB device specified at time of module insertion");
  973. info("Warning: This is not guaranteed to work");
  974. info("Using a newer kernel is preferred to this method");
  975. info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x",
  976. vendor, product);
  977. }
  978. retval = usb_serial_register(&handspring_device);
  979. if (retval)
  980. goto failed_handspring_register;
  981. retval = usb_serial_register(&clie_3_5_device);
  982. if (retval)
  983. goto failed_clie_3_5_register;
  984. retval = usb_serial_register(&clie_5_device);
  985. if (retval)
  986. goto failed_clie_5_register;
  987. retval = usb_register(&visor_driver);
  988. if (retval)
  989. goto failed_usb_register;
  990. info(DRIVER_DESC " " DRIVER_VERSION);
  991. return 0;
  992. failed_usb_register:
  993. usb_serial_deregister(&clie_5_device);
  994. failed_clie_5_register:
  995. usb_serial_deregister(&clie_3_5_device);
  996. failed_clie_3_5_register:
  997. usb_serial_deregister(&handspring_device);
  998. failed_handspring_register:
  999. return retval;
  1000. }
  1001. static void __exit visor_exit (void)
  1002. {
  1003. usb_deregister (&visor_driver);
  1004. usb_serial_deregister (&handspring_device);
  1005. usb_serial_deregister (&clie_3_5_device);
  1006. usb_serial_deregister (&clie_5_device);
  1007. }
  1008. module_init(visor_init);
  1009. module_exit(visor_exit);
  1010. MODULE_AUTHOR( DRIVER_AUTHOR );
  1011. MODULE_DESCRIPTION( DRIVER_DESC );
  1012. MODULE_LICENSE("GPL");
  1013. module_param(debug, bool, S_IRUGO | S_IWUSR);
  1014. MODULE_PARM_DESC(debug, "Debug enabled or not");
  1015. module_param(stats, bool, S_IRUGO | S_IWUSR);
  1016. MODULE_PARM_DESC(stats, "Enables statistics or not");
  1017. module_param(vendor, ushort, 0);
  1018. MODULE_PARM_DESC(vendor, "User specified vendor ID");
  1019. module_param(product, ushort, 0);
  1020. MODULE_PARM_DESC(product, "User specified product ID");