visor.c 19 KB

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