visor.c 36 KB

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