visor.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID),
  238. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  239. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID),
  240. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  241. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID),
  242. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  243. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID),
  244. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  245. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID),
  246. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  247. { }, /* optional parameter entry */
  248. { } /* Terminating entry */
  249. };
  250. static struct usb_device_id clie_id_5_table [] = {
  251. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID),
  252. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  253. { }, /* optional parameter entry */
  254. { } /* Terminating entry */
  255. };
  256. static struct usb_device_id clie_id_3_5_table [] = {
  257. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  258. { } /* Terminating entry */
  259. };
  260. static struct usb_device_id id_table_combined [] = {
  261. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
  262. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) },
  263. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) },
  264. { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
  265. { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
  266. { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
  267. { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
  268. { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID) },
  269. { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
  270. { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
  271. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID) },
  272. { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650) },
  273. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID) },
  274. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE31_ID) },
  275. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID) },
  276. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  277. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
  278. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
  279. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID) },
  280. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID) },
  281. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID) },
  282. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID) },
  283. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID) },
  284. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID) },
  285. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID) },
  286. { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID) },
  287. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID) },
  288. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID) },
  289. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID) },
  290. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID) },
  291. { }, /* optional parameter entry */
  292. { } /* Terminating entry */
  293. };
  294. MODULE_DEVICE_TABLE (usb, id_table_combined);
  295. static struct usb_driver visor_driver = {
  296. .owner = THIS_MODULE,
  297. .name = "visor",
  298. .probe = usb_serial_probe,
  299. .disconnect = usb_serial_disconnect,
  300. .id_table = id_table_combined,
  301. };
  302. /* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */
  303. static struct usb_serial_device_type handspring_device = {
  304. .owner = THIS_MODULE,
  305. .name = "Handspring Visor / Palm OS",
  306. .short_name = "visor",
  307. .id_table = id_table,
  308. .num_interrupt_in = NUM_DONT_CARE,
  309. .num_bulk_in = 2,
  310. .num_bulk_out = 2,
  311. .num_ports = 2,
  312. .open = visor_open,
  313. .close = visor_close,
  314. .throttle = visor_throttle,
  315. .unthrottle = visor_unthrottle,
  316. .attach = treo_attach,
  317. .probe = visor_probe,
  318. .calc_num_ports = visor_calc_num_ports,
  319. .shutdown = visor_shutdown,
  320. .ioctl = visor_ioctl,
  321. .set_termios = visor_set_termios,
  322. .write = visor_write,
  323. .write_room = visor_write_room,
  324. .chars_in_buffer = visor_chars_in_buffer,
  325. .write_bulk_callback = visor_write_bulk_callback,
  326. .read_bulk_callback = visor_read_bulk_callback,
  327. .read_int_callback = visor_read_int_callback,
  328. };
  329. /* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */
  330. static struct usb_serial_device_type clie_5_device = {
  331. .owner = THIS_MODULE,
  332. .name = "Sony Clie 5.0",
  333. .short_name = "clie_5",
  334. .id_table = clie_id_5_table,
  335. .num_interrupt_in = NUM_DONT_CARE,
  336. .num_bulk_in = 2,
  337. .num_bulk_out = 2,
  338. .num_ports = 2,
  339. .open = visor_open,
  340. .close = visor_close,
  341. .throttle = visor_throttle,
  342. .unthrottle = visor_unthrottle,
  343. .attach = clie_5_attach,
  344. .probe = visor_probe,
  345. .calc_num_ports = visor_calc_num_ports,
  346. .shutdown = visor_shutdown,
  347. .ioctl = visor_ioctl,
  348. .set_termios = visor_set_termios,
  349. .write = visor_write,
  350. .write_room = visor_write_room,
  351. .chars_in_buffer = visor_chars_in_buffer,
  352. .write_bulk_callback = visor_write_bulk_callback,
  353. .read_bulk_callback = visor_read_bulk_callback,
  354. .read_int_callback = visor_read_int_callback,
  355. };
  356. /* device info for the Sony Clie OS version 3.5 */
  357. static struct usb_serial_device_type clie_3_5_device = {
  358. .owner = THIS_MODULE,
  359. .name = "Sony Clie 3.5",
  360. .short_name = "clie_3.5",
  361. .id_table = clie_id_3_5_table,
  362. .num_interrupt_in = 0,
  363. .num_bulk_in = 1,
  364. .num_bulk_out = 1,
  365. .num_ports = 1,
  366. .open = visor_open,
  367. .close = visor_close,
  368. .throttle = visor_throttle,
  369. .unthrottle = visor_unthrottle,
  370. .attach = clie_3_5_startup,
  371. .ioctl = visor_ioctl,
  372. .set_termios = visor_set_termios,
  373. .write = visor_write,
  374. .write_room = visor_write_room,
  375. .chars_in_buffer = visor_chars_in_buffer,
  376. .write_bulk_callback = visor_write_bulk_callback,
  377. .read_bulk_callback = visor_read_bulk_callback,
  378. };
  379. struct visor_private {
  380. spinlock_t lock;
  381. int bytes_in;
  382. int bytes_out;
  383. int outstanding_urbs;
  384. int throttled;
  385. };
  386. /* number of outstanding urbs to prevent userspace DoS from happening */
  387. #define URB_UPPER_LIMIT 42
  388. static int stats;
  389. /******************************************************************************
  390. * Handspring Visor specific driver functions
  391. ******************************************************************************/
  392. static int visor_open (struct usb_serial_port *port, struct file *filp)
  393. {
  394. struct usb_serial *serial = port->serial;
  395. struct visor_private *priv = usb_get_serial_port_data(port);
  396. unsigned long flags;
  397. int result = 0;
  398. dbg("%s - port %d", __FUNCTION__, port->number);
  399. if (!port->read_urb) {
  400. /* this is needed for some brain dead Sony devices */
  401. dev_err(&port->dev, "Device lied about number of ports, please use a lower one.\n");
  402. return -ENODEV;
  403. }
  404. spin_lock_irqsave(&priv->lock, flags);
  405. priv->bytes_in = 0;
  406. priv->bytes_out = 0;
  407. priv->outstanding_urbs = 0;
  408. priv->throttled = 0;
  409. spin_unlock_irqrestore(&priv->lock, flags);
  410. /*
  411. * Force low_latency on so that our tty_push actually forces the data
  412. * through, otherwise it is scheduled, and with high data rates (like
  413. * with OHCI) data can get lost.
  414. */
  415. if (port->tty)
  416. port->tty->low_latency = 1;
  417. /* Start reading from the device */
  418. usb_fill_bulk_urb (port->read_urb, serial->dev,
  419. usb_rcvbulkpipe (serial->dev,
  420. port->bulk_in_endpointAddress),
  421. port->read_urb->transfer_buffer,
  422. port->read_urb->transfer_buffer_length,
  423. visor_read_bulk_callback, port);
  424. result = usb_submit_urb(port->read_urb, GFP_KERNEL);
  425. if (result) {
  426. dev_err(&port->dev, "%s - failed submitting read urb, error %d\n",
  427. __FUNCTION__, result);
  428. goto exit;
  429. }
  430. if (port->interrupt_in_urb) {
  431. dbg("%s - adding interrupt input for treo", __FUNCTION__);
  432. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  433. if (result)
  434. dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n",
  435. __FUNCTION__, result);
  436. }
  437. exit:
  438. return result;
  439. }
  440. static void visor_close (struct usb_serial_port *port, struct file * filp)
  441. {
  442. struct visor_private *priv = usb_get_serial_port_data(port);
  443. unsigned char *transfer_buffer;
  444. dbg("%s - port %d", __FUNCTION__, port->number);
  445. /* shutdown our urbs */
  446. usb_kill_urb(port->read_urb);
  447. if (port->interrupt_in_urb)
  448. usb_kill_urb(port->interrupt_in_urb);
  449. /* Try to send shutdown message, if the device is gone, this will just fail. */
  450. transfer_buffer = kmalloc (0x12, GFP_KERNEL);
  451. if (transfer_buffer) {
  452. usb_control_msg (port->serial->dev,
  453. usb_rcvctrlpipe(port->serial->dev, 0),
  454. VISOR_CLOSE_NOTIFICATION, 0xc2,
  455. 0x0000, 0x0000,
  456. transfer_buffer, 0x12, 300);
  457. kfree (transfer_buffer);
  458. }
  459. if (stats)
  460. dev_info(&port->dev, "Bytes In = %d Bytes Out = %d\n",
  461. priv->bytes_in, priv->bytes_out);
  462. }
  463. static int visor_write (struct usb_serial_port *port, const unsigned char *buf, int count)
  464. {
  465. struct visor_private *priv = usb_get_serial_port_data(port);
  466. struct usb_serial *serial = port->serial;
  467. struct urb *urb;
  468. unsigned char *buffer;
  469. unsigned long flags;
  470. int status;
  471. dbg("%s - port %d", __FUNCTION__, port->number);
  472. spin_lock_irqsave(&priv->lock, flags);
  473. if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
  474. spin_unlock_irqrestore(&priv->lock, flags);
  475. dbg("%s - write limit hit\n", __FUNCTION__);
  476. return 0;
  477. }
  478. spin_unlock_irqrestore(&priv->lock, flags);
  479. buffer = kmalloc (count, GFP_ATOMIC);
  480. if (!buffer) {
  481. dev_err(&port->dev, "out of memory\n");
  482. return -ENOMEM;
  483. }
  484. urb = usb_alloc_urb(0, GFP_ATOMIC);
  485. if (!urb) {
  486. dev_err(&port->dev, "no more free urbs\n");
  487. kfree (buffer);
  488. return -ENOMEM;
  489. }
  490. memcpy (buffer, buf, count);
  491. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, buffer);
  492. usb_fill_bulk_urb (urb, serial->dev,
  493. usb_sndbulkpipe (serial->dev,
  494. port->bulk_out_endpointAddress),
  495. buffer, count,
  496. visor_write_bulk_callback, port);
  497. /* send it down the pipe */
  498. status = usb_submit_urb(urb, GFP_ATOMIC);
  499. if (status) {
  500. dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n",
  501. __FUNCTION__, status);
  502. count = status;
  503. kfree (buffer);
  504. } else {
  505. spin_lock_irqsave(&priv->lock, flags);
  506. ++priv->outstanding_urbs;
  507. priv->bytes_out += count;
  508. spin_unlock_irqrestore(&priv->lock, flags);
  509. }
  510. /* we are done with this urb, so let the host driver
  511. * really free it when it is finished with it */
  512. usb_free_urb (urb);
  513. return count;
  514. }
  515. static int visor_write_room (struct usb_serial_port *port)
  516. {
  517. dbg("%s - port %d", __FUNCTION__, port->number);
  518. /*
  519. * We really can take anything the user throws at us
  520. * but let's pick a nice big number to tell the tty
  521. * layer that we have lots of free space
  522. */
  523. return 2048;
  524. }
  525. static int visor_chars_in_buffer (struct usb_serial_port *port)
  526. {
  527. dbg("%s - port %d", __FUNCTION__, port->number);
  528. /*
  529. * We can't really account for how much data we
  530. * have sent out, but hasn't made it through to the
  531. * device, so just tell the tty layer that everything
  532. * is flushed.
  533. */
  534. return 0;
  535. }
  536. static void visor_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
  537. {
  538. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  539. struct visor_private *priv = usb_get_serial_port_data(port);
  540. unsigned long flags;
  541. /* free up the transfer buffer, as usb_free_urb() does not do this */
  542. kfree (urb->transfer_buffer);
  543. dbg("%s - port %d", __FUNCTION__, port->number);
  544. if (urb->status)
  545. dbg("%s - nonzero write bulk status received: %d",
  546. __FUNCTION__, urb->status);
  547. spin_lock_irqsave(&priv->lock, flags);
  548. --priv->outstanding_urbs;
  549. spin_unlock_irqrestore(&priv->lock, flags);
  550. schedule_work(&port->work);
  551. }
  552. static void visor_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
  553. {
  554. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  555. struct visor_private *priv = usb_get_serial_port_data(port);
  556. unsigned char *data = urb->transfer_buffer;
  557. struct tty_struct *tty;
  558. unsigned long flags;
  559. int i;
  560. int throttled;
  561. int result;
  562. dbg("%s - port %d", __FUNCTION__, port->number);
  563. if (urb->status) {
  564. dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
  565. return;
  566. }
  567. usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data);
  568. tty = port->tty;
  569. if (tty && urb->actual_length) {
  570. for (i = 0; i < urb->actual_length ; ++i) {
  571. /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
  572. if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
  573. tty_flip_buffer_push(tty);
  574. }
  575. /* this doesn't actually push the data through unless tty->low_latency is set */
  576. tty_insert_flip_char(tty, data[i], 0);
  577. }
  578. tty_flip_buffer_push(tty);
  579. }
  580. spin_lock_irqsave(&priv->lock, flags);
  581. priv->bytes_in += urb->actual_length;
  582. throttled = priv->throttled;
  583. spin_unlock_irqrestore(&priv->lock, flags);
  584. /* Continue trying to always read if we should */
  585. if (!throttled) {
  586. usb_fill_bulk_urb (port->read_urb, port->serial->dev,
  587. usb_rcvbulkpipe(port->serial->dev,
  588. port->bulk_in_endpointAddress),
  589. port->read_urb->transfer_buffer,
  590. port->read_urb->transfer_buffer_length,
  591. visor_read_bulk_callback, port);
  592. result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
  593. if (result)
  594. dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
  595. }
  596. return;
  597. }
  598. static void visor_read_int_callback (struct urb *urb, struct pt_regs *regs)
  599. {
  600. struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
  601. int result;
  602. switch (urb->status) {
  603. case 0:
  604. /* success */
  605. break;
  606. case -ECONNRESET:
  607. case -ENOENT:
  608. case -ESHUTDOWN:
  609. /* this urb is terminated, clean up */
  610. dbg("%s - urb shutting down with status: %d",
  611. __FUNCTION__, urb->status);
  612. return;
  613. default:
  614. dbg("%s - nonzero urb status received: %d",
  615. __FUNCTION__, urb->status);
  616. goto exit;
  617. }
  618. /*
  619. * This information is still unknown what it can be used for.
  620. * If anyone has an idea, please let the author know...
  621. *
  622. * Rumor has it this endpoint is used to notify when data
  623. * is ready to be read from the bulk ones.
  624. */
  625. usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
  626. urb->actual_length, urb->transfer_buffer);
  627. exit:
  628. result = usb_submit_urb (urb, GFP_ATOMIC);
  629. if (result)
  630. dev_err(&urb->dev->dev, "%s - Error %d submitting interrupt urb\n",
  631. __FUNCTION__, result);
  632. }
  633. static void visor_throttle (struct usb_serial_port *port)
  634. {
  635. struct visor_private *priv = usb_get_serial_port_data(port);
  636. unsigned long flags;
  637. dbg("%s - port %d", __FUNCTION__, port->number);
  638. spin_lock_irqsave(&priv->lock, flags);
  639. priv->throttled = 1;
  640. spin_unlock_irqrestore(&priv->lock, flags);
  641. }
  642. static void visor_unthrottle (struct usb_serial_port *port)
  643. {
  644. struct visor_private *priv = usb_get_serial_port_data(port);
  645. unsigned long flags;
  646. int result;
  647. dbg("%s - port %d", __FUNCTION__, port->number);
  648. spin_lock_irqsave(&priv->lock, flags);
  649. priv->throttled = 0;
  650. spin_unlock_irqrestore(&priv->lock, flags);
  651. port->read_urb->dev = port->serial->dev;
  652. result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
  653. if (result)
  654. dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
  655. }
  656. static int palm_os_3_probe (struct usb_serial *serial, const struct usb_device_id *id)
  657. {
  658. struct device *dev = &serial->dev->dev;
  659. struct visor_connection_info *connection_info;
  660. unsigned char *transfer_buffer;
  661. char *string;
  662. int retval = 0;
  663. int i;
  664. int num_ports = 0;
  665. dbg("%s", __FUNCTION__);
  666. transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL);
  667. if (!transfer_buffer) {
  668. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __FUNCTION__,
  669. sizeof(*connection_info));
  670. return -ENOMEM;
  671. }
  672. /* send a get connection info request */
  673. retval = usb_control_msg (serial->dev,
  674. usb_rcvctrlpipe(serial->dev, 0),
  675. VISOR_GET_CONNECTION_INFORMATION,
  676. 0xc2, 0x0000, 0x0000, transfer_buffer,
  677. sizeof(*connection_info), 300);
  678. if (retval < 0) {
  679. dev_err(dev, "%s - error %d getting connection information\n",
  680. __FUNCTION__, retval);
  681. goto exit;
  682. }
  683. if (retval == sizeof(*connection_info)) {
  684. connection_info = (struct visor_connection_info *)transfer_buffer;
  685. num_ports = le16_to_cpu(connection_info->num_ports);
  686. for (i = 0; i < num_ports; ++i) {
  687. switch (connection_info->connections[i].port_function_id) {
  688. case VISOR_FUNCTION_GENERIC:
  689. string = "Generic";
  690. break;
  691. case VISOR_FUNCTION_DEBUGGER:
  692. string = "Debugger";
  693. break;
  694. case VISOR_FUNCTION_HOTSYNC:
  695. string = "HotSync";
  696. break;
  697. case VISOR_FUNCTION_CONSOLE:
  698. string = "Console";
  699. break;
  700. case VISOR_FUNCTION_REMOTE_FILE_SYS:
  701. string = "Remote File System";
  702. break;
  703. default:
  704. string = "unknown";
  705. break;
  706. }
  707. dev_info(dev, "%s: port %d, is for %s use\n",
  708. serial->type->name,
  709. connection_info->connections[i].port, string);
  710. }
  711. }
  712. /*
  713. * Handle devices that report invalid stuff here.
  714. */
  715. if (num_ports == 0 || num_ports > 2) {
  716. dev_warn (dev, "%s: No valid connect info available\n",
  717. serial->type->name);
  718. num_ports = 2;
  719. }
  720. dev_info(dev, "%s: Number of ports: %d\n", serial->type->name,
  721. num_ports);
  722. /*
  723. * save off our num_ports info so that we can use it in the
  724. * calc_num_ports callback
  725. */
  726. usb_set_serial_data(serial, (void *)(long)num_ports);
  727. /* ask for the number of bytes available, but ignore the response as it is broken */
  728. retval = usb_control_msg (serial->dev,
  729. usb_rcvctrlpipe(serial->dev, 0),
  730. VISOR_REQUEST_BYTES_AVAILABLE,
  731. 0xc2, 0x0000, 0x0005, transfer_buffer,
  732. 0x02, 300);
  733. if (retval < 0)
  734. dev_err(dev, "%s - error %d getting bytes available request\n",
  735. __FUNCTION__, retval);
  736. retval = 0;
  737. exit:
  738. kfree (transfer_buffer);
  739. return retval;
  740. }
  741. static int palm_os_4_probe (struct usb_serial *serial, const struct usb_device_id *id)
  742. {
  743. struct device *dev = &serial->dev->dev;
  744. struct palm_ext_connection_info *connection_info;
  745. unsigned char *transfer_buffer;
  746. int retval;
  747. dbg("%s", __FUNCTION__);
  748. transfer_buffer = kmalloc (sizeof (*connection_info), GFP_KERNEL);
  749. if (!transfer_buffer) {
  750. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __FUNCTION__,
  751. sizeof(*connection_info));
  752. return -ENOMEM;
  753. }
  754. retval = usb_control_msg (serial->dev,
  755. usb_rcvctrlpipe(serial->dev, 0),
  756. PALM_GET_EXT_CONNECTION_INFORMATION,
  757. 0xc2, 0x0000, 0x0000, transfer_buffer,
  758. sizeof (*connection_info), 300);
  759. if (retval < 0)
  760. dev_err(dev, "%s - error %d getting connection info\n",
  761. __FUNCTION__, retval);
  762. else
  763. usb_serial_debug_data(debug, &serial->dev->dev, __FUNCTION__,
  764. retval, transfer_buffer);
  765. kfree (transfer_buffer);
  766. return 0;
  767. }
  768. static int visor_probe (struct usb_serial *serial, const struct usb_device_id *id)
  769. {
  770. int retval = 0;
  771. int (*startup) (struct usb_serial *serial, const struct usb_device_id *id);
  772. dbg("%s", __FUNCTION__);
  773. if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
  774. err("active config #%d != 1 ??",
  775. serial->dev->actconfig->desc.bConfigurationValue);
  776. return -ENODEV;
  777. }
  778. if (id->driver_info) {
  779. startup = (void *)id->driver_info;
  780. retval = startup(serial, id);
  781. }
  782. return retval;
  783. }
  784. static int visor_calc_num_ports (struct usb_serial *serial)
  785. {
  786. int num_ports = (int)(long)(usb_get_serial_data(serial));
  787. if (num_ports)
  788. usb_set_serial_data(serial, NULL);
  789. return num_ports;
  790. }
  791. static int generic_startup(struct usb_serial *serial)
  792. {
  793. struct visor_private *priv;
  794. int i;
  795. for (i = 0; i < serial->num_ports; ++i) {
  796. priv = kmalloc (sizeof(*priv), GFP_KERNEL);
  797. if (!priv)
  798. return -ENOMEM;
  799. memset (priv, 0x00, sizeof(*priv));
  800. spin_lock_init(&priv->lock);
  801. usb_set_serial_port_data(serial->port[i], priv);
  802. }
  803. return 0;
  804. }
  805. static int clie_3_5_startup (struct usb_serial *serial)
  806. {
  807. struct device *dev = &serial->dev->dev;
  808. int result;
  809. u8 data;
  810. dbg("%s", __FUNCTION__);
  811. /*
  812. * Note that PEG-300 series devices expect the following two calls.
  813. */
  814. /* get the config number */
  815. result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  816. USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
  817. 0, 0, &data, 1, 3000);
  818. if (result < 0) {
  819. dev_err(dev, "%s: get config number failed: %d\n", __FUNCTION__, result);
  820. return result;
  821. }
  822. if (result != 1) {
  823. dev_err(dev, "%s: get config number bad return length: %d\n", __FUNCTION__, result);
  824. return -EIO;
  825. }
  826. /* get the interface number */
  827. result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  828. USB_REQ_GET_INTERFACE,
  829. USB_DIR_IN | USB_RECIP_INTERFACE,
  830. 0, 0, &data, 1, 3000);
  831. if (result < 0) {
  832. dev_err(dev, "%s: get interface number failed: %d\n", __FUNCTION__, result);
  833. return result;
  834. }
  835. if (result != 1) {
  836. dev_err(dev, "%s: get interface number bad return length: %d\n", __FUNCTION__, result);
  837. return -EIO;
  838. }
  839. return generic_startup(serial);
  840. }
  841. static int treo_attach (struct usb_serial *serial)
  842. {
  843. struct usb_serial_port *swap_port;
  844. /* Only do this endpoint hack for the Handspring devices with
  845. * interrupt in endpoints, which for now are the Treo devices. */
  846. if (!((le16_to_cpu(serial->dev->descriptor.idVendor) == HANDSPRING_VENDOR_ID) ||
  847. (le16_to_cpu(serial->dev->descriptor.idVendor) == KYOCERA_VENDOR_ID)) ||
  848. (serial->num_interrupt_in == 0))
  849. goto generic_startup;
  850. dbg("%s", __FUNCTION__);
  851. /*
  852. * It appears that Treos and Kyoceras want to use the
  853. * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint,
  854. * so let's swap the 1st and 2nd bulk in and interrupt endpoints.
  855. * Note that swapping the bulk out endpoints would break lots of
  856. * apps that want to communicate on the second port.
  857. */
  858. #define COPY_PORT(dest, src) \
  859. dest->read_urb = src->read_urb; \
  860. dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress; \
  861. dest->bulk_in_buffer = src->bulk_in_buffer; \
  862. dest->interrupt_in_urb = src->interrupt_in_urb; \
  863. dest->interrupt_in_endpointAddress = src->interrupt_in_endpointAddress; \
  864. dest->interrupt_in_buffer = src->interrupt_in_buffer;
  865. swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL);
  866. if (!swap_port)
  867. return -ENOMEM;
  868. COPY_PORT(swap_port, serial->port[0]);
  869. COPY_PORT(serial->port[0], serial->port[1]);
  870. COPY_PORT(serial->port[1], swap_port);
  871. kfree(swap_port);
  872. generic_startup:
  873. return generic_startup(serial);
  874. }
  875. static int clie_5_attach (struct usb_serial *serial)
  876. {
  877. dbg("%s", __FUNCTION__);
  878. /* TH55 registers 2 ports.
  879. Communication in from the UX50/TH55 uses bulk_in_endpointAddress from port 0
  880. Communication out to the UX50/TH55 uses bulk_out_endpointAddress from port 1
  881. Lets do a quick and dirty mapping
  882. */
  883. /* some sanity check */
  884. if (serial->num_ports < 2)
  885. return -1;
  886. /* port 0 now uses the modified endpoint Address */
  887. serial->port[0]->bulk_out_endpointAddress = serial->port[1]->bulk_out_endpointAddress;
  888. return generic_startup(serial);
  889. }
  890. static void visor_shutdown (struct usb_serial *serial)
  891. {
  892. dbg("%s", __FUNCTION__);
  893. }
  894. static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
  895. {
  896. dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
  897. return -ENOIOCTLCMD;
  898. }
  899. /* This function is all nice and good, but we don't change anything based on it :) */
  900. static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios)
  901. {
  902. unsigned int cflag;
  903. dbg("%s - port %d", __FUNCTION__, port->number);
  904. if ((!port->tty) || (!port->tty->termios)) {
  905. dbg("%s - no tty structures", __FUNCTION__);
  906. return;
  907. }
  908. cflag = port->tty->termios->c_cflag;
  909. /* check that they really want us to change something */
  910. if (old_termios) {
  911. if ((cflag == old_termios->c_cflag) &&
  912. (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
  913. dbg("%s - nothing to change...", __FUNCTION__);
  914. return;
  915. }
  916. }
  917. /* get the byte size */
  918. switch (cflag & CSIZE) {
  919. case CS5: dbg("%s - data bits = 5", __FUNCTION__); break;
  920. case CS6: dbg("%s - data bits = 6", __FUNCTION__); break;
  921. case CS7: dbg("%s - data bits = 7", __FUNCTION__); break;
  922. default:
  923. case CS8: dbg("%s - data bits = 8", __FUNCTION__); break;
  924. }
  925. /* determine the parity */
  926. if (cflag & PARENB)
  927. if (cflag & PARODD)
  928. dbg("%s - parity = odd", __FUNCTION__);
  929. else
  930. dbg("%s - parity = even", __FUNCTION__);
  931. else
  932. dbg("%s - parity = none", __FUNCTION__);
  933. /* figure out the stop bits requested */
  934. if (cflag & CSTOPB)
  935. dbg("%s - stop bits = 2", __FUNCTION__);
  936. else
  937. dbg("%s - stop bits = 1", __FUNCTION__);
  938. /* figure out the flow control settings */
  939. if (cflag & CRTSCTS)
  940. dbg("%s - RTS/CTS is enabled", __FUNCTION__);
  941. else
  942. dbg("%s - RTS/CTS is disabled", __FUNCTION__);
  943. /* determine software flow control */
  944. if (I_IXOFF(port->tty))
  945. dbg("%s - XON/XOFF is enabled, XON = %2x, XOFF = %2x",
  946. __FUNCTION__, START_CHAR(port->tty), STOP_CHAR(port->tty));
  947. else
  948. dbg("%s - XON/XOFF is disabled", __FUNCTION__);
  949. /* get the baud rate wanted */
  950. dbg("%s - baud rate = %d", __FUNCTION__, tty_get_baud_rate(port->tty));
  951. return;
  952. }
  953. static int __init visor_init (void)
  954. {
  955. int i, retval;
  956. /* Only if parameters were passed to us */
  957. if ((vendor>0) && (product>0)) {
  958. struct usb_device_id usb_dev_temp[]=
  959. {{USB_DEVICE(vendor, product),
  960. .driver_info = (kernel_ulong_t)&palm_os_4_probe }};
  961. /* Find the last entry in id_table */
  962. for (i=0; ; i++) {
  963. if (id_table[i].idVendor==0) {
  964. id_table[i] = usb_dev_temp[0];
  965. break;
  966. }
  967. }
  968. /* Find the last entry in id_table_combined */
  969. for (i=0; ; i++) {
  970. if (id_table_combined[i].idVendor==0) {
  971. id_table_combined[i] = usb_dev_temp[0];
  972. break;
  973. }
  974. }
  975. info("Untested USB device specified at time of module insertion");
  976. info("Warning: This is not guaranteed to work");
  977. info("Using a newer kernel is preferred to this method");
  978. info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x",
  979. vendor, product);
  980. }
  981. retval = usb_serial_register(&handspring_device);
  982. if (retval)
  983. goto failed_handspring_register;
  984. retval = usb_serial_register(&clie_3_5_device);
  985. if (retval)
  986. goto failed_clie_3_5_register;
  987. retval = usb_serial_register(&clie_5_device);
  988. if (retval)
  989. goto failed_clie_5_register;
  990. retval = usb_register(&visor_driver);
  991. if (retval)
  992. goto failed_usb_register;
  993. info(DRIVER_DESC " " DRIVER_VERSION);
  994. return 0;
  995. failed_usb_register:
  996. usb_serial_deregister(&clie_5_device);
  997. failed_clie_5_register:
  998. usb_serial_deregister(&clie_3_5_device);
  999. failed_clie_3_5_register:
  1000. usb_serial_deregister(&handspring_device);
  1001. failed_handspring_register:
  1002. return retval;
  1003. }
  1004. static void __exit visor_exit (void)
  1005. {
  1006. usb_deregister (&visor_driver);
  1007. usb_serial_deregister (&handspring_device);
  1008. usb_serial_deregister (&clie_3_5_device);
  1009. usb_serial_deregister (&clie_5_device);
  1010. }
  1011. module_init(visor_init);
  1012. module_exit(visor_exit);
  1013. MODULE_AUTHOR( DRIVER_AUTHOR );
  1014. MODULE_DESCRIPTION( DRIVER_DESC );
  1015. MODULE_LICENSE("GPL");
  1016. module_param(debug, bool, S_IRUGO | S_IWUSR);
  1017. MODULE_PARM_DESC(debug, "Debug enabled or not");
  1018. module_param(stats, bool, S_IRUGO | S_IWUSR);
  1019. MODULE_PARM_DESC(stats, "Enables statistics or not");
  1020. module_param(vendor, ushort, 0);
  1021. MODULE_PARM_DESC(vendor, "User specified vendor ID");
  1022. module_param(product, ushort, 0);
  1023. MODULE_PARM_DESC(product, "User specified product ID");