visor.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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
  9. * modify it under the terms of the GNU General Public License version
  10. * 2 as published by the Free Software Foundation.
  11. *
  12. * See Documentation/usb/usb-serial.txt for more information on using this
  13. * driver
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/init.h>
  19. #include <linux/slab.h>
  20. #include <linux/tty.h>
  21. #include <linux/tty_driver.h>
  22. #include <linux/tty_flip.h>
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/usb.h>
  28. #include <linux/usb/serial.h>
  29. #include <linux/usb/cdc.h>
  30. #include "visor.h"
  31. /*
  32. * Version Information
  33. */
  34. #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
  35. #define DRIVER_DESC "USB HandSpring Visor / Palm OS driver"
  36. /* function prototypes for a handspring visor */
  37. static int visor_open(struct tty_struct *tty, struct usb_serial_port *port);
  38. static void visor_close(struct usb_serial_port *port);
  39. static int visor_probe(struct usb_serial *serial,
  40. const struct usb_device_id *id);
  41. static int visor_calc_num_ports(struct usb_serial *serial);
  42. static void visor_read_int_callback(struct urb *urb);
  43. static int clie_3_5_startup(struct usb_serial *serial);
  44. static int treo_attach(struct usb_serial *serial);
  45. static int clie_5_attach(struct usb_serial *serial);
  46. static int palm_os_3_probe(struct usb_serial *serial,
  47. const struct usb_device_id *id);
  48. static int palm_os_4_probe(struct usb_serial *serial,
  49. const struct usb_device_id *id);
  50. /* Parameters that may be passed into the module. */
  51. static int debug;
  52. static __u16 vendor;
  53. static __u16 product;
  54. static struct usb_device_id id_table [] = {
  55. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID),
  56. .driver_info = (kernel_ulong_t)&palm_os_3_probe },
  57. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID),
  58. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  59. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID),
  60. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  61. { USB_DEVICE(GSPDA_VENDOR_ID, GSPDA_XPLORE_M68_ID),
  62. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  63. { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID),
  64. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  65. { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID),
  66. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  67. { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID),
  68. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  69. { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID),
  70. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  71. { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID),
  72. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  73. { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID),
  74. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  75. { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID),
  76. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  77. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID),
  78. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  79. { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650),
  80. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  81. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID),
  82. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  83. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID),
  84. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  85. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID),
  86. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  87. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID),
  88. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  89. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID),
  90. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  91. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID),
  92. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  93. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID),
  94. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  95. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID),
  96. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  97. { USB_DEVICE(ACER_VENDOR_ID, ACER_S10_ID),
  98. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  99. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID),
  100. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  101. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID),
  102. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  103. { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID),
  104. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  105. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID),
  106. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  107. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID),
  108. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  109. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID),
  110. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  111. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID),
  112. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  113. { }, /* optional parameter entry */
  114. { } /* Terminating entry */
  115. };
  116. static struct usb_device_id clie_id_5_table [] = {
  117. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID),
  118. .driver_info = (kernel_ulong_t)&palm_os_4_probe },
  119. { }, /* optional parameter entry */
  120. { } /* Terminating entry */
  121. };
  122. static struct usb_device_id clie_id_3_5_table [] = {
  123. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  124. { } /* Terminating entry */
  125. };
  126. static struct usb_device_id id_table_combined [] = {
  127. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
  128. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) },
  129. { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) },
  130. { USB_DEVICE(GSPDA_VENDOR_ID, GSPDA_XPLORE_M68_ID) },
  131. { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
  132. { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
  133. { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
  134. { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
  135. { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID) },
  136. { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
  137. { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
  138. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID) },
  139. { USB_DEVICE(PALM_VENDOR_ID, PALM_TREO_650) },
  140. { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID) },
  141. { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID) },
  142. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
  143. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
  144. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
  145. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID) },
  146. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID) },
  147. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID) },
  148. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID) },
  149. { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID) },
  150. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID) },
  151. { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SPH_I500_ID) },
  152. { USB_DEVICE(TAPWAVE_VENDOR_ID, TAPWAVE_ZODIAC_ID) },
  153. { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID) },
  154. { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID) },
  155. { USB_DEVICE(KYOCERA_VENDOR_ID, KYOCERA_7135_ID) },
  156. { USB_DEVICE(FOSSIL_VENDOR_ID, FOSSIL_ABACUS_ID) },
  157. { }, /* optional parameter entry */
  158. { } /* Terminating entry */
  159. };
  160. MODULE_DEVICE_TABLE(usb, id_table_combined);
  161. static struct usb_driver visor_driver = {
  162. .name = "visor",
  163. .probe = usb_serial_probe,
  164. .disconnect = usb_serial_disconnect,
  165. .id_table = id_table_combined,
  166. .no_dynamic_id = 1,
  167. };
  168. /* All of the device info needed for the Handspring Visor,
  169. and Palm 4.0 devices */
  170. static struct usb_serial_driver handspring_device = {
  171. .driver = {
  172. .owner = THIS_MODULE,
  173. .name = "visor",
  174. },
  175. .description = "Handspring Visor / Palm OS",
  176. .usb_driver = &visor_driver,
  177. .id_table = id_table,
  178. .num_ports = 2,
  179. .bulk_out_size = 256,
  180. .open = visor_open,
  181. .close = visor_close,
  182. .throttle = usb_serial_generic_throttle,
  183. .unthrottle = usb_serial_generic_unthrottle,
  184. .attach = treo_attach,
  185. .probe = visor_probe,
  186. .calc_num_ports = visor_calc_num_ports,
  187. .read_int_callback = visor_read_int_callback,
  188. };
  189. /* All of the device info needed for the Clie UX50, TH55 Palm 5.0 devices */
  190. static struct usb_serial_driver clie_5_device = {
  191. .driver = {
  192. .owner = THIS_MODULE,
  193. .name = "clie_5",
  194. },
  195. .description = "Sony Clie 5.0",
  196. .usb_driver = &visor_driver,
  197. .id_table = clie_id_5_table,
  198. .num_ports = 2,
  199. .bulk_out_size = 256,
  200. .open = visor_open,
  201. .close = visor_close,
  202. .throttle = usb_serial_generic_throttle,
  203. .unthrottle = usb_serial_generic_unthrottle,
  204. .attach = clie_5_attach,
  205. .probe = visor_probe,
  206. .calc_num_ports = visor_calc_num_ports,
  207. .read_int_callback = visor_read_int_callback,
  208. };
  209. /* device info for the Sony Clie OS version 3.5 */
  210. static struct usb_serial_driver clie_3_5_device = {
  211. .driver = {
  212. .owner = THIS_MODULE,
  213. .name = "clie_3.5",
  214. },
  215. .description = "Sony Clie 3.5",
  216. .usb_driver = &visor_driver,
  217. .id_table = clie_id_3_5_table,
  218. .num_ports = 1,
  219. .bulk_out_size = 256,
  220. .open = visor_open,
  221. .close = visor_close,
  222. .throttle = usb_serial_generic_throttle,
  223. .unthrottle = usb_serial_generic_unthrottle,
  224. .attach = clie_3_5_startup,
  225. };
  226. /******************************************************************************
  227. * Handspring Visor specific driver functions
  228. ******************************************************************************/
  229. static int visor_open(struct tty_struct *tty, struct usb_serial_port *port)
  230. {
  231. int result = 0;
  232. dbg("%s - port %d", __func__, port->number);
  233. if (!port->read_urb) {
  234. /* this is needed for some brain dead Sony devices */
  235. dev_err(&port->dev, "Device lied about number of ports, please use a lower one.\n");
  236. return -ENODEV;
  237. }
  238. /* Start reading from the device */
  239. result = usb_serial_generic_open(tty, port);
  240. if (result)
  241. goto exit;
  242. if (port->interrupt_in_urb) {
  243. dbg("%s - adding interrupt input for treo", __func__);
  244. result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  245. if (result)
  246. dev_err(&port->dev,
  247. "%s - failed submitting interrupt urb, error %d\n",
  248. __func__, result);
  249. }
  250. exit:
  251. return result;
  252. }
  253. static void visor_close(struct usb_serial_port *port)
  254. {
  255. unsigned char *transfer_buffer;
  256. dbg("%s - port %d", __func__, port->number);
  257. /* shutdown our urbs */
  258. usb_serial_generic_close(port);
  259. usb_kill_urb(port->interrupt_in_urb);
  260. mutex_lock(&port->serial->disc_mutex);
  261. if (!port->serial->disconnected) {
  262. /* Try to send shutdown message, unless the device is gone */
  263. transfer_buffer = kmalloc(0x12, GFP_KERNEL);
  264. if (transfer_buffer) {
  265. usb_control_msg(port->serial->dev,
  266. usb_rcvctrlpipe(port->serial->dev, 0),
  267. VISOR_CLOSE_NOTIFICATION, 0xc2,
  268. 0x0000, 0x0000,
  269. transfer_buffer, 0x12, 300);
  270. kfree(transfer_buffer);
  271. }
  272. }
  273. mutex_unlock(&port->serial->disc_mutex);
  274. }
  275. static void visor_read_int_callback(struct urb *urb)
  276. {
  277. struct usb_serial_port *port = urb->context;
  278. int status = urb->status;
  279. int result;
  280. switch (status) {
  281. case 0:
  282. /* success */
  283. break;
  284. case -ECONNRESET:
  285. case -ENOENT:
  286. case -ESHUTDOWN:
  287. /* this urb is terminated, clean up */
  288. dbg("%s - urb shutting down with status: %d",
  289. __func__, status);
  290. return;
  291. default:
  292. dbg("%s - nonzero urb status received: %d",
  293. __func__, status);
  294. goto exit;
  295. }
  296. /*
  297. * This information is still unknown what it can be used for.
  298. * If anyone has an idea, please let the author know...
  299. *
  300. * Rumor has it this endpoint is used to notify when data
  301. * is ready to be read from the bulk ones.
  302. */
  303. usb_serial_debug_data(debug, &port->dev, __func__,
  304. urb->actual_length, urb->transfer_buffer);
  305. exit:
  306. result = usb_submit_urb(urb, GFP_ATOMIC);
  307. if (result)
  308. dev_err(&urb->dev->dev,
  309. "%s - Error %d submitting interrupt urb\n",
  310. __func__, result);
  311. }
  312. static int palm_os_3_probe(struct usb_serial *serial,
  313. const struct usb_device_id *id)
  314. {
  315. struct device *dev = &serial->dev->dev;
  316. struct visor_connection_info *connection_info;
  317. unsigned char *transfer_buffer;
  318. char *string;
  319. int retval = 0;
  320. int i;
  321. int num_ports = 0;
  322. dbg("%s", __func__);
  323. transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
  324. if (!transfer_buffer) {
  325. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
  326. sizeof(*connection_info));
  327. return -ENOMEM;
  328. }
  329. /* send a get connection info request */
  330. retval = usb_control_msg(serial->dev,
  331. usb_rcvctrlpipe(serial->dev, 0),
  332. VISOR_GET_CONNECTION_INFORMATION,
  333. 0xc2, 0x0000, 0x0000, transfer_buffer,
  334. sizeof(*connection_info), 300);
  335. if (retval < 0) {
  336. dev_err(dev, "%s - error %d getting connection information\n",
  337. __func__, retval);
  338. goto exit;
  339. }
  340. if (retval == sizeof(*connection_info)) {
  341. connection_info = (struct visor_connection_info *)
  342. transfer_buffer;
  343. num_ports = le16_to_cpu(connection_info->num_ports);
  344. for (i = 0; i < num_ports; ++i) {
  345. switch (
  346. connection_info->connections[i].port_function_id) {
  347. case VISOR_FUNCTION_GENERIC:
  348. string = "Generic";
  349. break;
  350. case VISOR_FUNCTION_DEBUGGER:
  351. string = "Debugger";
  352. break;
  353. case VISOR_FUNCTION_HOTSYNC:
  354. string = "HotSync";
  355. break;
  356. case VISOR_FUNCTION_CONSOLE:
  357. string = "Console";
  358. break;
  359. case VISOR_FUNCTION_REMOTE_FILE_SYS:
  360. string = "Remote File System";
  361. break;
  362. default:
  363. string = "unknown";
  364. break;
  365. }
  366. dev_info(dev, "%s: port %d, is for %s use\n",
  367. serial->type->description,
  368. connection_info->connections[i].port, string);
  369. }
  370. }
  371. /*
  372. * Handle devices that report invalid stuff here.
  373. */
  374. if (num_ports == 0 || num_ports > 2) {
  375. dev_warn(dev, "%s: No valid connect info available\n",
  376. serial->type->description);
  377. num_ports = 2;
  378. }
  379. dev_info(dev, "%s: Number of ports: %d\n", serial->type->description,
  380. num_ports);
  381. /*
  382. * save off our num_ports info so that we can use it in the
  383. * calc_num_ports callback
  384. */
  385. usb_set_serial_data(serial, (void *)(long)num_ports);
  386. /* ask for the number of bytes available, but ignore the
  387. response as it is broken */
  388. retval = usb_control_msg(serial->dev,
  389. usb_rcvctrlpipe(serial->dev, 0),
  390. VISOR_REQUEST_BYTES_AVAILABLE,
  391. 0xc2, 0x0000, 0x0005, transfer_buffer,
  392. 0x02, 300);
  393. if (retval < 0)
  394. dev_err(dev, "%s - error %d getting bytes available request\n",
  395. __func__, retval);
  396. retval = 0;
  397. exit:
  398. kfree(transfer_buffer);
  399. return retval;
  400. }
  401. static int palm_os_4_probe(struct usb_serial *serial,
  402. const struct usb_device_id *id)
  403. {
  404. struct device *dev = &serial->dev->dev;
  405. struct palm_ext_connection_info *connection_info;
  406. unsigned char *transfer_buffer;
  407. int retval;
  408. dbg("%s", __func__);
  409. transfer_buffer = kmalloc(sizeof(*connection_info), GFP_KERNEL);
  410. if (!transfer_buffer) {
  411. dev_err(dev, "%s - kmalloc(%Zd) failed.\n", __func__,
  412. sizeof(*connection_info));
  413. return -ENOMEM;
  414. }
  415. retval = usb_control_msg(serial->dev,
  416. usb_rcvctrlpipe(serial->dev, 0),
  417. PALM_GET_EXT_CONNECTION_INFORMATION,
  418. 0xc2, 0x0000, 0x0000, transfer_buffer,
  419. sizeof(*connection_info), 300);
  420. if (retval < 0)
  421. dev_err(dev, "%s - error %d getting connection info\n",
  422. __func__, retval);
  423. else
  424. usb_serial_debug_data(debug, &serial->dev->dev, __func__,
  425. retval, transfer_buffer);
  426. kfree(transfer_buffer);
  427. return 0;
  428. }
  429. static int visor_probe(struct usb_serial *serial,
  430. const struct usb_device_id *id)
  431. {
  432. int retval = 0;
  433. int (*startup)(struct usb_serial *serial,
  434. const struct usb_device_id *id);
  435. dbg("%s", __func__);
  436. /*
  437. * some Samsung Android phones in modem mode have the same ID
  438. * as SPH-I500, but they are ACM devices, so dont bind to them
  439. */
  440. if (id->idVendor == SAMSUNG_VENDOR_ID &&
  441. id->idProduct == SAMSUNG_SPH_I500_ID &&
  442. serial->dev->descriptor.bDeviceClass == USB_CLASS_COMM &&
  443. serial->dev->descriptor.bDeviceSubClass ==
  444. USB_CDC_SUBCLASS_ACM)
  445. return -ENODEV;
  446. if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
  447. dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
  448. serial->dev->actconfig->desc.bConfigurationValue);
  449. return -ENODEV;
  450. }
  451. if (id->driver_info) {
  452. startup = (void *)id->driver_info;
  453. retval = startup(serial, id);
  454. }
  455. return retval;
  456. }
  457. static int visor_calc_num_ports(struct usb_serial *serial)
  458. {
  459. int num_ports = (int)(long)(usb_get_serial_data(serial));
  460. if (num_ports)
  461. usb_set_serial_data(serial, NULL);
  462. return num_ports;
  463. }
  464. static int clie_3_5_startup(struct usb_serial *serial)
  465. {
  466. struct device *dev = &serial->dev->dev;
  467. int result;
  468. u8 *data;
  469. dbg("%s", __func__);
  470. data = kmalloc(1, GFP_KERNEL);
  471. if (!data)
  472. return -ENOMEM;
  473. /*
  474. * Note that PEG-300 series devices expect the following two calls.
  475. */
  476. /* get the config number */
  477. result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  478. USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
  479. 0, 0, data, 1, 3000);
  480. if (result < 0) {
  481. dev_err(dev, "%s: get config number failed: %d\n",
  482. __func__, result);
  483. goto out;
  484. }
  485. if (result != 1) {
  486. dev_err(dev, "%s: get config number bad return length: %d\n",
  487. __func__, result);
  488. result = -EIO;
  489. goto out;
  490. }
  491. /* get the interface number */
  492. result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  493. USB_REQ_GET_INTERFACE,
  494. USB_DIR_IN | USB_RECIP_INTERFACE,
  495. 0, 0, data, 1, 3000);
  496. if (result < 0) {
  497. dev_err(dev, "%s: get interface number failed: %d\n",
  498. __func__, result);
  499. goto out;
  500. }
  501. if (result != 1) {
  502. dev_err(dev,
  503. "%s: get interface number bad return length: %d\n",
  504. __func__, result);
  505. result = -EIO;
  506. goto out;
  507. }
  508. result = 0;
  509. out:
  510. kfree(data);
  511. return result;
  512. }
  513. static int treo_attach(struct usb_serial *serial)
  514. {
  515. struct usb_serial_port *swap_port;
  516. /* Only do this endpoint hack for the Handspring devices with
  517. * interrupt in endpoints, which for now are the Treo devices. */
  518. if (!((le16_to_cpu(serial->dev->descriptor.idVendor)
  519. == HANDSPRING_VENDOR_ID) ||
  520. (le16_to_cpu(serial->dev->descriptor.idVendor)
  521. == KYOCERA_VENDOR_ID)) ||
  522. (serial->num_interrupt_in == 0))
  523. return 0;
  524. dbg("%s", __func__);
  525. /*
  526. * It appears that Treos and Kyoceras want to use the
  527. * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint,
  528. * so let's swap the 1st and 2nd bulk in and interrupt endpoints.
  529. * Note that swapping the bulk out endpoints would break lots of
  530. * apps that want to communicate on the second port.
  531. */
  532. #define COPY_PORT(dest, src) \
  533. do { \
  534. dest->read_urb = src->read_urb; \
  535. dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress;\
  536. dest->bulk_in_buffer = src->bulk_in_buffer; \
  537. dest->interrupt_in_urb = src->interrupt_in_urb; \
  538. dest->interrupt_in_endpointAddress = \
  539. src->interrupt_in_endpointAddress;\
  540. dest->interrupt_in_buffer = src->interrupt_in_buffer; \
  541. } while (0);
  542. swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL);
  543. if (!swap_port)
  544. return -ENOMEM;
  545. COPY_PORT(swap_port, serial->port[0]);
  546. COPY_PORT(serial->port[0], serial->port[1]);
  547. COPY_PORT(serial->port[1], swap_port);
  548. kfree(swap_port);
  549. return 0;
  550. }
  551. static int clie_5_attach(struct usb_serial *serial)
  552. {
  553. struct usb_serial_port *port;
  554. unsigned int pipe;
  555. int j;
  556. dbg("%s", __func__);
  557. /* TH55 registers 2 ports.
  558. Communication in from the UX50/TH55 uses bulk_in_endpointAddress
  559. from port 0. Communication out to the UX50/TH55 uses
  560. bulk_out_endpointAddress from port 1
  561. Lets do a quick and dirty mapping
  562. */
  563. /* some sanity check */
  564. if (serial->num_ports < 2)
  565. return -1;
  566. /* port 0 now uses the modified endpoint Address */
  567. port = serial->port[0];
  568. port->bulk_out_endpointAddress =
  569. serial->port[1]->bulk_out_endpointAddress;
  570. pipe = usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress);
  571. for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j)
  572. port->write_urbs[j]->pipe = pipe;
  573. return 0;
  574. }
  575. static int __init visor_init(void)
  576. {
  577. int i, retval;
  578. /* Only if parameters were passed to us */
  579. if (vendor > 0 && product > 0) {
  580. struct usb_device_id usb_dev_temp[] = {
  581. {
  582. USB_DEVICE(vendor, product),
  583. .driver_info =
  584. (kernel_ulong_t) &palm_os_4_probe
  585. }
  586. };
  587. /* Find the last entry in id_table */
  588. for (i = 0;; i++) {
  589. if (id_table[i].idVendor == 0) {
  590. id_table[i] = usb_dev_temp[0];
  591. break;
  592. }
  593. }
  594. /* Find the last entry in id_table_combined */
  595. for (i = 0;; i++) {
  596. if (id_table_combined[i].idVendor == 0) {
  597. id_table_combined[i] = usb_dev_temp[0];
  598. break;
  599. }
  600. }
  601. printk(KERN_INFO KBUILD_MODNAME
  602. ": Untested USB device specified at time of module insertion\n");
  603. printk(KERN_INFO KBUILD_MODNAME
  604. ": Warning: This is not guaranteed to work\n");
  605. printk(KERN_INFO KBUILD_MODNAME
  606. ": Using a newer kernel is preferred to this method\n");
  607. printk(KERN_INFO KBUILD_MODNAME
  608. ": Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x\n",
  609. vendor, product);
  610. }
  611. retval = usb_serial_register(&handspring_device);
  612. if (retval)
  613. goto failed_handspring_register;
  614. retval = usb_serial_register(&clie_3_5_device);
  615. if (retval)
  616. goto failed_clie_3_5_register;
  617. retval = usb_serial_register(&clie_5_device);
  618. if (retval)
  619. goto failed_clie_5_register;
  620. retval = usb_register(&visor_driver);
  621. if (retval)
  622. goto failed_usb_register;
  623. printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
  624. return 0;
  625. failed_usb_register:
  626. usb_serial_deregister(&clie_5_device);
  627. failed_clie_5_register:
  628. usb_serial_deregister(&clie_3_5_device);
  629. failed_clie_3_5_register:
  630. usb_serial_deregister(&handspring_device);
  631. failed_handspring_register:
  632. return retval;
  633. }
  634. static void __exit visor_exit (void)
  635. {
  636. usb_deregister(&visor_driver);
  637. usb_serial_deregister(&handspring_device);
  638. usb_serial_deregister(&clie_3_5_device);
  639. usb_serial_deregister(&clie_5_device);
  640. }
  641. module_init(visor_init);
  642. module_exit(visor_exit);
  643. MODULE_AUTHOR(DRIVER_AUTHOR);
  644. MODULE_DESCRIPTION(DRIVER_DESC);
  645. MODULE_LICENSE("GPL");
  646. module_param(debug, bool, S_IRUGO | S_IWUSR);
  647. MODULE_PARM_DESC(debug, "Debug enabled or not");
  648. module_param(vendor, ushort, 0);
  649. MODULE_PARM_DESC(vendor, "User specified vendor ID");
  650. module_param(product, ushort, 0);
  651. MODULE_PARM_DESC(product, "User specified product ID");